-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsend_email.py
executable file
·59 lines (46 loc) · 1.7 KB
/
send_email.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/python
# encoding:utf-8
# filename: mail.py
import smtplib
from email.mime.text import MIMEText
from modconf import *
import time, sys
def email(HOST, PORT, FROM, PASSWORD, TOs, SUBJECT, BODY):
msg = MIMEText(BODY, 'plain', _charset='UTF-8')
msg['To'] = ', '.join(TOs)
msg['From'] = FROM
msg['Subject'] = SUBJECT
content = []
content.append('From: ' + FROM)
content.append('To: ' + ', '.join(TOs))
content.append('Subject: ' + SUBJECT)
content.append('')
content.append(BODY)
data = '\r\n'.join(content)
data = msg.as_string()
server = smtplib.SMTP_SSL()
server.connect(HOST, PORT)
# server.starttls()
server.login(FROM, PASSWORD)
server.sendmail(FROM, TOs, data)
server.quit()
def SendEmailMessage(touser, subject, message):
""" 发送邮件消息 """
a = getConfig('email')
email(a['emailhost'], a['emailport'],a['emailuser'], a['emailpassword'], touser, subject, message)
# 如果单个邮箱发送比较慢的话可以使用多个邮箱发送邮件
# t = int(time.time() * 1000)
# if t%3 ==0:
# email(a['emailhost'], a['emailport'],a['emailuser'], a['emailpassword'], touser, subject, message)
# elif t%3 ==1:
# email(a['emailhost'], a['emailport'],a['emailuser'], a['emailpassword'], touser, subject, message)
# else:
# email(a['emailhost'], a['emailport'],a['emailuser'], a['emailpassword'], touser, subject, message)
print 'done'
if __name__ == "__main__":
if len(sys.argv) != 4:
print 'aaa',sys.argv
print 'invalidate arguments'
print 'eg: [email protected] title msgcontent'
exit(1)
SendEmailMessage(sys.argv[1], sys.argv[2], sys.argv[3])