python 利用 smtplib发邮件
1 import smtplib
2 from email.mime.text import MIMEText
3
4 title = "request build error"
5 content = "request build error"
6 to_address = ["menghui.lv@mobvista.com"]
7
8
9 def send_email(username, passwd, recv, title, content, email_host="hwsmtp.exmail.qq.com", port=25):
10 msg = MIMEText(content)
11 msg["from"] = "menghui"
12 msg["Subject"] = title
13 smtp = smtplib.SMTP(host=email_host, port=port, timeout=120)
14 smtp.login(username, passwd)
15 smtp.set_debuglevel(1)
16 smtp.sendmail(username, recv, msg.as_string())
17 smtp.quit()
18
19
20 def send(title, content, to_address):
21 email_user = "mobvista_dsp_report@mobvista.com"
22 email_pwd = "Mobvista123"
23 send_email(email_user, email_pwd, to_address, title, content)
24
25
26 if __name__ == "__main__":
27 send(title, content, to_address)