发送测试报告附件

发布时间 2023-08-15 14:21:24作者: 马越月
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="15735108014@163.com"
password="XBYCSQXGQMBJMESD" #授权码
#接收邮件地址
receview="1170064379@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 = "15735108014@163.com"
password = "XBYCSQXGQMBJMESD" # 授权码
# 接收邮件地址
receview = "1170064379@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')
'''