import smtplibfrom email.mime.text import MIMETextimport osdef send_report(report): sender = "8000@sfmail.sf-express.com" receiver = "8000@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\80002907\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()
来源:https://www.cnblogs.com/wenjing2019/p/11990355.html