Skip to content

Commit

Permalink
更新邮件模块
Browse files Browse the repository at this point in the history
  • Loading branch information
pooneyy committed Sep 8, 2023
1 parent 0bd6494 commit a6e503a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ gobal_config:
# 腾讯云函数专用,用于向用户邮箱发送日志。
SMTP:
smtpHost: "" # SMTP服务器,例如smtp.qq.com
smtpPort: 25 # SMTP端口,例如465
smtpUser: "" # SMTP用户名
smtpKey: "" # SMTP密码
smtp_sender: "" # 发件人邮箱地址
Expand Down
5 changes: 3 additions & 2 deletions sendLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
except FileNotFoundError:...

smtpHost : str = config.get("gobal_config").get("SMTP").get("smtpHost")
stmpPort : int = config.get("gobal_config").get("SMTP").get("stmpPort")
smtpUser : str = config.get("gobal_config").get("SMTP").get("smtpUser")
smtpKey : str = config.get("gobal_config").get("SMTP").get("smtpKey")
smtp_sender : str = config.get("gobal_config").get("SMTP").get("smtp_sender")
Expand All @@ -26,10 +27,10 @@ def sendLog(projectName):
mail['From'] = formataddr((smtp_senderName, smtp_sender), "utf-8")
mail['To'] = formataddr((None, smtp_sendto), "utf-8")
mail.attach(MIMEText("日志见附件", 'html', 'utf-8'))
att = MIMEText(open(attachmentsFileName, 'r').read(), 'base64', 'utf-8')
att = MIMEText(open(attachmentsFileName, 'r', encoding='utf-8').read(), 'base64', 'utf-8')
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = f"attachment; filename = {projectName + '.txt'}"
mail.attach(att)
smtpObj = smtplib.SMTP_SSL(smtpHost, 465)
smtpObj = smtplib.SMTP(smtpHost, stmpPort)
smtpObj.login(smtpUser, smtpKey)
smtpObj.sendmail(smtp_sender, smtp_sendto, mail.as_string())

0 comments on commit a6e503a

Please sign in to comment.