python接口测试之如何发送邮件

可以参考菜鸟教程:http://www.runoob.com/python3/python3-smtp.html

import smtplib
import email.mime.multipart
import email.mime.text
msg=email.mime.multipart.MIMEMultipart()
msg['from']='mesunyueru@163.com'
msg['to']='mesunyueru@qq.com'
msg['subject']='给你的一封信'
content="你好"
txt=email.mime.text.MIMEText(content)
msg.attach(txt)
smtp=smtplib.SMTP()
smtp.connect('smtp.163.com')
smtp.login('mesunyueru@163.com',password)
smtp.sendmail('mesunyueru@163.com','mesunyueru@qq.com',str(msg))

  

 

posted @ 2018-06-15 19:37  水如如  阅读(176)  评论(0编辑  收藏  举报