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')
'''
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?