From 01966485d178ea19b6be283d5734500f73d4b28a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 25 Mar 2022 09:27:50 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- send_email.py | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/send_email.py b/send_email.py index 8e6e378c6..442281211 100644 --- a/send_email.py +++ b/send_email.py @@ -1,12 +1,11 @@ import mimetypes import os -from email.mime.application import MIMEApplication -from email.mime.base import MIMEBase -from email.mime.image import MIMEImage -from smtplib import SMTP_SSL -from email.mime.text import MIMEText -from email.mime.multipart import MIMEMultipart from email.header import Header +from email.mime.image import MIMEImage +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText +from smtplib import SMTP_SSL + from util.common import Conf @@ -19,44 +18,49 @@ class Sendemail: self.sender_pwd = conf.getconf("Email").sender_pwd self.receiver = conf.getconf("Email").receiver self.ccer = conf.getconf("Email").ccer - self.att=conf.getconf("Email").att + self.att = conf.getconf("Email").att def send_email(self, title, body_text): try: smtp = SMTP_SSL(self.host_server, self.port) smtp.login(self.sender_email, self.sender_pwd) # 登陆 msg = MIMEMultipart() - msg['Subject'] = Header(title) # 主题 - msg['From'] = self.sender_email # 发件人 - msg['To'] = self.receiver # 收件人 - msg['Cc'] = self.ccer # 抄送 - msg.attach(MIMEText(body_text, 'html')) # 正文 + msg["Subject"] = Header(title) # 主题 + msg["From"] = self.sender_email # 发件人 + msg["To"] = self.receiver # 收件人 + msg["Cc"] = self.ccer # 抄送 + msg.attach(MIMEText(body_text, "html")) # 正文 - #添加附件 - for filename in self.att.split(','): + # 添加附件 + for filename in self.att.split(","): if filename != None and os.path.exists(filename): ctype, encoding = mimetypes.guess_type(filename) if ctype is None or encoding is not None: ctype = "application/octet-stream" maintype, subtype = ctype.split("/", 1) - attachment = MIMEImage((lambda f: (f.read(), f.close()))(open(filename, "rb"))[0], _subtype = subtype) - attachment.add_header("Content-Disposition", "attachment", filename = filename.split('/')[len(filename.split('/'))-1]) + attachment = MIMEImage( + (lambda f: (f.read(), f.close()))(open(filename, "rb"))[0], + _subtype=subtype, + ) + attachment.add_header( + "Content-Disposition", + "attachment", + filename=filename.split("/")[len(filename.split("/")) - 1], + ) msg.attach(attachment) - smtp.sendmail(self.sender_email, self.receiver.split(','), msg.as_string()) # 发送邮件 + smtp.sendmail( + self.sender_email, self.receiver.split(","), msg.as_string() + ) # 发送邮件 smtp.quit() # 结束会话 except Exception as error: print(error) -if __name__ == '__main__': +if __name__ == "__main__": title = "内核自动化测试报告" mail_txt = "
点链接查看详细测试结果
http://10.20.33.147:43005/index.html#behaviors" # mail_txt = "111111" sdm = Sendemail() sdm.send_email(title, mail_txt) - - - -