-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmail_api.py
More file actions
38 lines (33 loc) · 845 Bytes
/
mail_api.py
File metadata and controls
38 lines (33 loc) · 845 Bytes
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
30
31
32
33
34
35
36
37
38
#!/usr/bin/python
#coding:utf-8
import smtplib
from email.mime.text import MIMEText
import sys
mail_host = ''
mail_user = ''
mail_pass = ''
mail_postfix = ''
def send_mail(to_list,subject,file):
me = mail_user
file_object = open(file)
try:
mail_content = file_object.read()
finally:
file_object.close( )
msg = MIMEText(mail_content)
msg['Subject'] = subject
msg['From'] = me
msg['to'] = ",".join(to_list)
try:
s = smtplib.SMTP()
#s.set_debuglevel(1)
s.connect(mail_host)
s.login(mail_user,mail_pass)
s.sendmail(me,to_list,msg.as_string())
s.close()
return True
except Exception,e:
print str(e)
return False
if __name__ == "__main__":
send_mail(sys.argv[1], sys.argv[2], sys.argv[3])