Salibra

It's the best of time and it's the worst of time.

导航

Python扩展:邮件发送

Posted on 2015-11-11 15:58  salibra  阅读(185)  评论(0)    收藏  举报
 1 import smtplib
 2 from email.mime.text import MIMEText
 3 from email.utils import formataddr
 4  
 5  
 6 msg = MIMEText('邮件内容', 'plain', 'utf-8')
 7 msg['From'] = formataddr(["武沛齐",'wptawy@126.com'])
 8 msg['To'] = formataddr(["走人",'424662508@qq.com'])
 9 msg['Subject'] = "主题"
10  
11 server = smtplib.SMTP("smtp.126.com", 25)
12 server.login("wptawy@126.com", "邮箱密码")
13 server.sendmail('wptawy@126.com', ['424662508@qq.com',], msg.as_string())
14 server.quit()