-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMail_html.py
38 lines (29 loc) · 1017 Bytes
/
Mail_html.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
import smtplib
import logging
import os
from email.mime.text import MIMEText
# logging.basicConfig(filename = os.path.join(os.getcwd(), 'monitor-hdfs.log'), level = logging.INFO,format = '%(asctime)s - %(levelname)s: %(message)s')
mailto = ""
mail_host = "smtp.qiye.163.com"
mail_user = "[email protected]"
mail_pass = "xxxx"
mail_postfix = "xxx.com"
def send_mail(sub, content, to):
me = "data_warning" + "<" + mail_user + "@" + mail_postfix + ">"
# msg = MIMEText(content,_subtype='plain',_charset='gb2312')
msg = MIMEText(content, _subtype='html', _charset='utf-8')
msg['Subject'] = sub
msg['From'] = me
msg['To'] = ", ".join(to)
try:
server = smtplib.SMTP()
server.connect(mail_host)
server.login(mail_user, mail_pass)
server.sendmail(me, to, msg.as_string())
server.close()
logging.info("MAIL SENT")
return True
except Exception, e:
logging.info("FAIL")
logging.info(str(e))
return False