[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2022-03-25 09:27:50 +00:00
parent 03dc236b22
commit 01966485d1
1 changed files with 26 additions and 22 deletions

View File

@ -1,12 +1,11 @@
import mimetypes import mimetypes
import os 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.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 from util.common import Conf
@ -26,37 +25,42 @@ class Sendemail:
smtp = SMTP_SSL(self.host_server, self.port) smtp = SMTP_SSL(self.host_server, self.port)
smtp.login(self.sender_email, self.sender_pwd) # 登陆 smtp.login(self.sender_email, self.sender_pwd) # 登陆
msg = MIMEMultipart() msg = MIMEMultipart()
msg['Subject'] = Header(title) # 主题 msg["Subject"] = Header(title) # 主题
msg['From'] = self.sender_email # 发件人 msg["From"] = self.sender_email # 发件人
msg['To'] = self.receiver # 收件人 msg["To"] = self.receiver # 收件人
msg['Cc'] = self.ccer # 抄送 msg["Cc"] = self.ccer # 抄送
msg.attach(MIMEText(body_text, 'html')) # 正文 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): if filename != None and os.path.exists(filename):
ctype, encoding = mimetypes.guess_type(filename) ctype, encoding = mimetypes.guess_type(filename)
if ctype is None or encoding is not None: if ctype is None or encoding is not None:
ctype = "application/octet-stream" ctype = "application/octet-stream"
maintype, subtype = ctype.split("/", 1) maintype, subtype = ctype.split("/", 1)
attachment = MIMEImage((lambda f: (f.read(), f.close()))(open(filename, "rb"))[0], _subtype = subtype) attachment = MIMEImage(
attachment.add_header("Content-Disposition", "attachment", filename = filename.split('/')[len(filename.split('/'))-1]) (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) 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() # 结束会话 smtp.quit() # 结束会话
except Exception as error: except Exception as error:
print(error) print(error)
if __name__ == '__main__': if __name__ == "__main__":
title = "内核自动化测试报告" title = "内核自动化测试报告"
mail_txt = "<p>点链接查看详细测试结果</p>http://10.20.33.147:43005/index.html#behaviors</p>" mail_txt = "<p>点链接查看详细测试结果</p>http://10.20.33.147:43005/index.html#behaviors</p>"
# mail_txt = "111111" # mail_txt = "111111"
sdm = Sendemail() sdm = Sendemail()
sdm.send_email(title, mail_txt) sdm.send_email(title, mail_txt)