1.创建send_mail.py
import smtplib, time
from email import encoders
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
def send_mail():
"""
使用163邮箱发送邮件
:return:
"""
print('执行完成,生成测试结果')
# 构建html测试报告的路径
report_path = 'report.html'
csv_path = 'result.csv'
mail_host = "***.163.com"
mail_user = '***'
mail_pass = "************" # 不是用户名对应的密码,而是163给的授权码
sender = "***@163.com" # 发件人
receivers = ['***@qq.com'] # 收件人
mail_postfix = "163.com"
...............此处省略 ............... ............... ...............
2. 执行顺序
首先执行pytest,生成报告,然后再执行python send_mail.py,发送邮件
发送成功后,可以看到2个附件,分别是report.html和result.csv.