import smtplib标签:__,username,测试报告,smtp,发送,附件,import,message,email From: https://www.cnblogs.com/mayueyue/p/17631170.html
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="[email protected]"
password="XBYCSQXGQMBJMESD" #授权码
#接收邮件地址
receview="[email protected]"
#创建邮件对象
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 = "[email protected]"
password = "XBYCSQXGQMBJMESD" # 授权码
# 接收邮件地址
receview = "[email protected]"
# 创建邮件对象
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')
'''