python自动化报告发送到邮件(qq邮箱)

 

 password 为上方的授权码

 smtpserver 为 (百度查一下 对应邮箱smtp服务器是多少)

 username (用户名为发送方的邮箱)

receiver(为接收人的邮箱) 

 


import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText


class EmailManage:
def send_emails(self):
#定义SMTP服务器
smtpserver = 'smtp.qq.com'

#发送邮件的用户名和客户端密码
username = 'aaa@qq.com'
password = 'zzz'(找到qq邮箱的)

#接收的邮件
receiver = 'aac@qq.com'

#创建邮件对象
message = MIMEMultipart('related')
subject = '自动化测试报告'
fujian = MIMEText(open('接口自动化测试报告.html','rb').read(),'html','utf-8')

#把邮件的信息组装到邮件对象里面
message['form']=username
message['to']=receiver
message['subject']=subject
message.attach(fujian)

#登录服务器 发送邮件
smtp = smtplib.SMTP()
smtp.connect(smtpserver)
smtp.login(username,password)
smtp.sendmail(username,receiver,message.as_string())
smtp.quit()

发送方法:可以比较老的一种就是直接通过电脑的定时任务,等报告生成出来之后,进行邮件的发出





posted @ 2022-10-19 15:00  CWZzzzz  阅读(145)  评论(0编辑  收藏  举报