diff --git a/config.example.yml b/config.example.yml index 76d0df5..aa1cc57 100644 --- a/config.example.yml +++ b/config.example.yml @@ -26,6 +26,7 @@ gobal_config: # 腾讯云函数专用,用于向用户邮箱发送日志。 SMTP: smtpHost: "" # SMTP服务器,例如smtp.qq.com + smtpPort: 25 # SMTP端口,例如465 smtpUser: "" # SMTP用户名 smtpKey: "" # SMTP密码 smtp_sender: "" # 发件人邮箱地址 diff --git a/sendLog.py b/sendLog.py index 04c118d..0314e06 100644 --- a/sendLog.py +++ b/sendLog.py @@ -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") @@ -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()) \ No newline at end of file