feat: IMAP 支持 SSL/STARTTLS 配置

This commit is contained in:
2026-07-02 22:18:51 +08:00
parent 05135ee0cc
commit d7daddf491
3 changed files with 10 additions and 1 deletions

View File

@@ -17,6 +17,8 @@ class EmailAccount:
imap_port: int
username: str
password: str
use_ssl: bool = True
use_starttls: bool = False
smtp: Optional[SmtpConfig] = None

View File

@@ -74,7 +74,12 @@ def _select_mailbox(conn, mailbox: str = "INBOX"):
def _login_and_prepare(account: EmailAccount):
logger.info("连接 %s:%d", account.imap_server, account.imap_port)
conn = imaplib.IMAP4_SSL(account.imap_server, account.imap_port)
if account.use_ssl:
conn = imaplib.IMAP4_SSL(account.imap_server, account.imap_port)
else:
conn = imaplib.IMAP4(account.imap_server, account.imap_port)
if account.use_starttls:
conn.starttls()
conn.login(account.username, account.password)
logger.info("登录成功: %s", account.username)
if _check_provider(account.username, _PROVIDERS_NEED_ID):