发送邮件
import smtplib
from email.mime.text import MIMEText
class sendmail:
def sendmail(self, path):
#读测试报告
f = open(path, 'rb')
mail_body = f.read()
f.close()
#设置邮箱
host = 'smtp.163.com'
port = 465
sender = 'daniel_402@163.com'
pwd = 'HDFASFASFSADF' #个人邮箱授权码
receiver = 'daniel_402@163.com' #这里设置的发送和接收为同一个地址,可更改为任意接收者
#设置邮件
msg = MIMEText(mail_body, 'HTML', 'UTF-8')
msg['subject'] = 'API测试报告发送'
msg['from'] = sender
msg['to'] = receiver
#做连接
s = smtplib.SMTP_SSL(host, port)
s.login(sender, pwd)
s.sendmail(sender, receiver, msg.as_string())
调用发送邮件模块,在生成测试报告的模块中添加代码:
#生成测试报告后,将测试报告以邮件形式进行发送
sendmail.sendmail(report_path)