MCPcopy Create free account
hub / github.com/smallfawn/QLScriptPublic / smtp

Function smtp

notify.py:679–725  ·  view source on GitHub ↗

使用 SMTP 邮件 推送消息。

(title: str, content: str)

Source from the content-addressed store, hash-verified

677
678
679def smtp(title: str, content: str) -> None:
680 """
681 使用 SMTP 邮件 推送消息。
682 """
683 if (
684 not push_config.get("SMTP_SERVER")
685 or not push_config.get("SMTP_SSL")
686 or not push_config.get("SMTP_EMAIL")
687 or not push_config.get("SMTP_PASSWORD")
688 or not push_config.get("SMTP_NAME")
689 ):
690 return
691 print("SMTP 邮件 服务启动")
692
693 message = MIMEText(content, "plain", "utf-8")
694 message["From"] = formataddr(
695 (
696 Header(push_config.get("SMTP_NAME"), "utf-8").encode(),
697 push_config.get("SMTP_EMAIL"),
698 )
699 )
700 message["To"] = formataddr(
701 (
702 Header(push_config.get("SMTP_NAME"), "utf-8").encode(),
703 push_config.get("SMTP_EMAIL"),
704 )
705 )
706 message["Subject"] = Header(title, "utf-8")
707
708 try:
709 smtp_server = (
710 smtplib.SMTP_SSL(push_config.get("SMTP_SERVER"))
711 if push_config.get("SMTP_SSL") == "true"
712 else smtplib.SMTP(push_config.get("SMTP_SERVER"))
713 )
714 smtp_server.login(
715 push_config.get("SMTP_EMAIL"), push_config.get("SMTP_PASSWORD")
716 )
717 smtp_server.sendmail(
718 push_config.get("SMTP_EMAIL"),
719 push_config.get("SMTP_EMAIL"),
720 message.as_bytes(),
721 )
722 smtp_server.close()
723 print("SMTP 邮件 推送成功!")
724 except Exception as e:
725 print(f"SMTP 邮件 推送失败!{e}")
726
727
728def pushme(title: str, content: str) -> None:

Callers

nothing calls this directly

Calls 3

printFunction · 0.70
getMethod · 0.45
loginMethod · 0.45

Tested by

no test coverage detected