发送测试报告

import smtplib
from email.mime.text import MIMEText
import os

def send_report(report):
sender = "000@sfmail.sf-express.com"
receiver = "000@sfmail.sf-express.com"
username = sender
password = "123456"
smtpsenderserver = "lsmtp.sf-express.com"


with open(report,"rb") as f:
sendmessage = f.read()


content = MIMEText(sendmessage, _subtype="html", _charset="utf-8")
content["from"] = sender
content["to"] = receiver
content["subject"] = u"测试报告标题"


smtp = smtplib.SMTP() # 初始化邮箱服务,实例化
smtp.connect(smtpsenderserver,"25")
smtp.login(username,password)
smtp.sendmail(sender,receiver,content.as_string())
smtp.close()

def findnewreport():
report_path = r"C:Users2907PycharmProjectsxuexi11281128 eport"
listreport = os.listdir(report_path)
listreport.sort(key=lambda f:os.path.getmtime(report_path+"\"+f))
newreport = listreport[-1]
send_report(newreport)


findnewreport()

原文地址:https://www.cnblogs.com/wenjing2019/p/11990355.html