feat(v1.1.0): add send mail support via Graph API and SMTP

This commit is contained in:
juanjuanjuanidea
2026-07-24 13:58:44 +08:00
parent 015a63043d
commit e5e1ef3a2d
4 changed files with 102 additions and 2 deletions
+22
View File
@@ -0,0 +1,22 @@
import smtplib
from email.message import EmailMessage
def send_mail_smtp(host: str, port: int, username: str, password: str, to_email: str, subject: str, body_text: str, use_tls: bool = True, use_ssl: bool = False) -> bool:
"""使用 SMTP 协议发送邮件"""
msg = EmailMessage()
msg["Subject"] = subject
msg["From"] = username
msg["To"] = to_email
msg.set_content(body_text)
if use_ssl:
with smtplib.SMTP_SSL(host, port, timeout=20) as server:
server.login(username, password)
server.send_message(msg)
else:
with smtplib.SMTP(host, port, timeout=20) as server:
if use_tls:
server.starttls()
server.login(username, password)
server.send_message(msg)
return True