发送测试报告

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:\Users\2907\PycharmProjects\xuexi1128\1128\report"
listreport = os.listdir(report_path)
listreport.sort(key=lambda f:os.path.getmtime(report_path+"\\"+f))
newreport = listreport[-1]
send_report(newreport)


findnewreport()

 


posted on 2019-12-05 16:49  wenjingtester  阅读(139)  评论(0编辑  收藏  举报