Commit b3cb69d6 authored by 王志伟's avatar 王志伟

send_email

parent 11c5de62
...@@ -8,6 +8,8 @@ from email.utils import formataddr ...@@ -8,6 +8,8 @@ from email.utils import formataddr
from email.mime.application import MIMEApplication from email.mime.application import MIMEApplication
import datetime import datetime
from email.mime.multipart import MIMEMultipart
my_sender='gaoyazhe@igengmei.com' my_sender='gaoyazhe@igengmei.com'
my_pass = 'VCrKTui99a7ALhiK' my_pass = 'VCrKTui99a7ALhiK'
my_user1='wangzhiwei@igengmei.com' my_user1='wangzhiwei@igengmei.com'
...@@ -16,16 +18,20 @@ def mail(): ...@@ -16,16 +18,20 @@ def mail():
pdfFile = 'test.txt' pdfFile = 'test.txt'
pdfApart = MIMEApplication(open(pdfFile, 'rb').read()) pdfApart = MIMEApplication(open(pdfFile, 'rb').read())
pdfApart.add_header('Content-Disposition', 'attachment', filename=pdfFile) pdfApart.add_header('Content-Disposition', 'attachment', filename=pdfFile)
m = MIMEMultipart()
m.attach(pdfApart)
m['Subject'] = 'title'
try: try:
text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttp://www.baidu.com" # text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttp://www.baidu.com"
msg = MIMEText(text, 'plain', 'utf-8') # msg = MIMEText(text, 'plain', 'utf-8')
msg['From'] = formataddr(["王志伟", my_sender]) # msg['From'] = formataddr(["王志伟", my_sender])
msg['To'] = my_user1 # msg['To'] = my_user1
msg['Subject'] = str(datetime.date.today()) + "-esmm多目标模型训练指标统计" # msg['Subject'] = str(datetime.date.today()) + "-esmm多目标模型训练指标统计"
server = smtplib.SMTP_SSL("smtp.exmail.qq.com", 465) server = smtplib.SMTP_SSL("smtp.exmail.qq.com", 465)
server.login(my_sender, my_pass) server.login(my_sender, my_pass)
server.sendmail(my_sender, [my_user1], msg.as_string()) server.sendmail(my_sender, [my_user1], m.as_string())
server.quit() server.quit()
except Exception: except Exception:
ret=False ret=False
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment