-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendmail_python.py
29 lines (21 loc) · 933 Bytes
/
sendmail_python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/python
from email.message import EmailMessage
from subprocess import Popen
def send_mail(mail_array):
for mail in mail_array:
file_name = "test.xls"
msg = EmailMessage()
msg["From"] = "[email protected]"
msg["To"] = mail
msg["Subject"] = "This is test"
msg.set_content(f"""
THIS IS TEST BODY
""")
with open(f'test.xlsx', 'rb' ) as f:
file_data = f.read()
file_name = 'test.xlsx'
msg.add_attachment(file_data, maintype="application", subtype="xlsx", filename = file_name )
p = Popen(["/usr/sbin/sendmail", "-t"], stdin=PIPE)
p.communicate(msg.as_string().encode())
send_mail(mail_array)