发送测试报告附件

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

class EmailManage:
def send_email(self,wenjian):
#服务器地址
smtpserver="smtp.163.com"
#发送邮件的用户名密码
username="xxx@163.com"
password="xxx" #授权码
#接收邮件地址
receview="xxx@qq.com"
#创建邮件对象
message = MIMEMultipart('related')
subject = "测试报告"
#fujian = MIMEText( open(wenjian,'rb').read(),'html','utf-8')
#fujian["Content-Type"] = 'application/octet-stream'
#fujian["Content-Type"] = 'application/octet-stream'
attachment = MIMEApplication(open(wenjian, 'rb').read())
attachment.add_header('Content-Disposition', 'attachment', filename=wenjian)
message.attach(attachment)


#把邮件对象组装
message["from"]=username
message['to']=receview
message['subject']=subject
message.attach(attachment)

smtp=smtplib.SMTP()
smtp.connect(smtpserver)
smtp.login(username,password)
smtp.sendmail(username,receview,message.as_string())
smtp.quit()
'''

if __name__ == '__main__':
EmailManage().send_email('/Users/didi/PycharmProjects/pythonProject3/reports/report.html')

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

class EmailManage:
def send_email(self, wenjian):
# 服务器地址
smtpserver = "smtp.163.com"
# 发送邮件的用户名密码
username = "xxx@163.com"
password = "xxx" # 授权码
# 接收邮件地址
receview = "xxx@qq.com"
# 创建邮件对象
message = MIMEMultipart('related')
subject = "测试报告"
fujian = MIMEText(open(wenjian, 'rb').read(), 'html', 'utf-8')
fujian["Content-Type"] = 'application/octet-stream'

# 把邮件对象组装
message["from"] = username
message['to'] = receview
message['subject'] = subject
message.attach(fujian)

smtp = smtplib.SMTP()
smtp.connect(smtpserver)
smtp.login(username, password)
smtp.sendmail(username, receview, message.as_string())
smtp.quit()


if __name__ == '__main__':
EmailManage().send_email('/Users/didi/PycharmProjects/pythonProject3/reports/2023-07-28 17:27:25测试报告.html')
'''
posted @   马越月  阅读(12)  评论(2编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示