import smtplib
from email.mime.text import MIMEText
from email.header import Header

#发送邮件服务器
smtpserver = 'smtp.qq.com'
#发送邮箱用户及密码
user = 'xxxx@qq.com'
password = '邮箱smtp服务授权码'
#发送邮箱
sender = 'xxx@qq.com'
#接收邮箱
receiver = 'xxx@163.com'
#发送邮件主题
subject = '最新环境部署,接口测试报告'

#邮件html格式
msg = MIMEText('<html><body><h1>测试报告</h1></body></html>', 'html', 'utf-8')
msg['Subject'] = Header(subject, 'utf-8')

#连接发送邮件
smtp = smtplib.SMTP_SSL()
smtp.connect(smtpserver,465)
smtp.login(user,password)
smtp.sendmail(sender, receiver,msg.as_string())
smtp.close()


↙↙↙阅读原文可查看相关链接,并与作者交流