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']='[email protected]'
msg['to']='[email protected]'
msg['subject']='给你的一封信'
content="你好"
txt=email.mime.text.MIMEText(content)
msg.attach(txt)
smtp=smtplib.SMTP()
smtp.connect('smtp.163.com')
smtp.login('[email protected]',password)
smtp.sendmail('[email protected]','[email protected]',str(msg))

  

猜你喜欢

转载自www.cnblogs.com/mesunyueru/p/9188779.html