Skip to content

Commit

Permalink
test_email的try
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoZuohong committed Dec 28, 2023
1 parent 5f70367 commit 6bc0f4f
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,23 +508,23 @@ def test_email():
enable_custom_smtp = conf["custom_smtp_server"]["enable"]
# 根据encryption键的值选择加密方法
encryption = conf["custom_smtp_server"]["encryption"]
if enable_custom_smtp == "False":
# 如果不用自定义用qq邮箱就使用TLS加密
smtp_server = "smtp.qq.com"
ssl_port = 465
s = smtplib.SMTP_SSL(smtp_server, ssl_port, timeout=10.0)
elif encryption == "starttls":
# 使用STARTTLS加密
s = smtplib.SMTP(smtp_server, ssl_port, timeout=10.0)
s.starttls()
else:
# 如果encryption键的值不是starttls,则使用默认的TLS加密
s = smtplib.SMTP_SSL(smtp_server, ssl_port, timeout=10.0)
try:
# 登录SMTP服务器
s.login(conf["account"], conf["pass_code"])
# 发送邮件
s.sendmail(conf["account"], conf["recipient"], msg.as_string())
if enable_custom_smtp == "False":
# 如果不用自定义用qq邮箱就使用TLS加密
smtp_server = "smtp.qq.com"
ssl_port = 465
s = smtplib.SMTP_SSL(smtp_server, ssl_port, timeout=10.0)
elif encryption == "starttls":
# 使用STARTTLS加密
s = smtplib.SMTP(smtp_server, ssl_port, timeout=10.0)
s.starttls()
else:
# 如果encryption键的值不是starttls,则使用默认的TLS加密
s = smtplib.SMTP_SSL(smtp_server, ssl_port, timeout=10.0)
# 登录SMTP服务器
s.login(conf["account"], conf["pass_code"])
# 发送邮件
s.sendmail(conf["account"], conf["recipient"], msg.as_string())
except Exception as e:
return "邮件发送失败!\n" + str(e)
return "邮件发送成功!"
Expand Down

0 comments on commit 6bc0f4f

Please sign in to comment.