菁英科技(卓目鸟学苑)- 专注软件测试菁英教育

标题: selenium-魏清-20210302 [打印本页]

作者: 5269    时间: 2021-3-2 19:57
标题: selenium-魏清-20210302
今日学习内容:
# 设置邮件速武器地址
smtpserver = 'smtp.163.com'
# 设置邮件服务器端口号
port = 25
# 发件人地址
sender = 'q695685524@163.com'
# 密码或授权码
password = 'q695685524'
# 收件人
receivers = '15091835804@163.com;wyl1035@163.com'
# 创建邮件对象
mail = MIMEMultipart()
# 初始化发件人
mail['from'] = sender
# 添加收件人
mail['to'] = receivers
# 添加主题
mail['subject'] = 'Ranzhi自动化测试报告'
# 添加附件
path = 'class/ranzhi3/ranzhi/report/report_2021-03-02_15-26-06.html'
with open(path,'rb') as file:
    report = file.read()
# 对附件进行编码
attachment = MIMEText(report,'base64','utf-8')
# 设置附件的类型
attachment['Content-Type'] = 'application/octet-stream'
# 设指附件的处理方式
attachment['Content-Disposition'] = ['attchement;filename=%s'%path.split('/')][-1]
# 添加附件
mail.attach(attachment)
# 生成正文
content = '''
<p>Dear Mike,</p>
<p>    这里是<u>樱花国际</u>,请您尽快到达</p>
<p>此致</p>
<p>Tom Cruse</p>
'''
# 对邮件正文进行编码
body = MIMEText(content,'html','utf-8')
# 添加正文
mail.attach(body)
# 创建SMTP对象
smtp = smtplib.SMTP()
# 连接服务器
smtp.connect(smtpserver,port)
# 登陆服务器
smtp.login(sender,password)
# 发送邮件
smtp.sendmail(sender,receivers.split(';'),mail.as_string())
# 关闭服务器
smtp.close()
print('邮件发送完毕!')






欢迎光临 菁英科技(卓目鸟学苑)- 专注软件测试菁英教育 (http://www.zmnxy.com/) Powered by Discuz! X3.4