发送HTML正文邮件

邮件正文中可以使用HTML标记
mail=MIMEText(mailbody, 'html', 'utf-8')

导入模块
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr
登录邮箱
smtp=smtplib.SMTP('smtp.163.com',25)
smtp.login('邮箱账户', '邮箱密码')
指定邮件信息
sender='发件人姓名<发件人邮件地址'
receiver='收件人1姓名<收件人1邮件地址'
mailbody = '''
某经理:<p>
    你好,第几轮接口自动化测试已经完成,测试报告参见附件,谢谢!
'''
注意:理论上所有邮箱均可以回车
发送邮件
mail=MIMEText(mailbody, 'html', 'utf-8')
mail['From']=formataddr(sender.split('<'))
mail['To']=formataddr(receiver.split('<'))
mail['Subject']='某项目自动化测试第几轮测试报告'
smtp.sendmail(sender, receiver, mail.as_string())
断开连接
smtp.quit()

使用qq邮箱发送HTML正文邮件报告测试组长

import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr

smtp = smtplib.SMTP('smtp.qq.com', 25)
smtp.login('779146330@qq.com', 'idggecuopmudbbai')
sender = '暄总<779146330@qq.com'
receiver = '小暄总<sunbx@tedu.cn'
mailbody = '''
暄总:<p>
    你好,第12轮接口自动化测试已经完成,测试报告参见附件,谢谢!
'''
mail = MIMEText(mailbody, 'html', 'utf-8')
mail['From'] = formataddr(sender.split('<'))
mail['To'] = formataddr(receiver.split('<'))
mail['Subject'] = '某项目自动化测试第几轮测试报告'
smtp.sendmail(sender, receiver, mail.as_string())
smtp.quit()

作者:暄总-tester