1.用yagmail发送邮件
-----通过pip安装: pip install yagmail
sendemail.py
import yagmail
# 把测试报告作为附件发送到指定邮箱
sender = 'XXXXXXXXX@163.com'
pwd = 'XXXXXXXXX'
receiver1 = 'XXXXXXXXX@qq.com'
# receiver2 = '接收者2@qq.com'
host1 = 'smtp.163.com'
def send_mail(report):
yag = yagmail.SMTP(user=sender, password=pwd, host=host1)
subject = '自动化测试报告'
contents = '请查看附件。'
yag.send([receiver1],subject,contents, [report])
print('email has send out !')
XXXX.py
# 在执行并生成测试报告后自动发送报告
send_mail(report)
2.python自带