feat: IMAP 支持 SSL/STARTTLS 配置
This commit is contained in:
@@ -3,6 +3,7 @@ email_accounts:
|
||||
imap_port: 993
|
||||
username: "your_email@gmail.com"
|
||||
password: "your_app_password"
|
||||
use_ssl: true
|
||||
smtp:
|
||||
server: "smtp.gmail.com"
|
||||
port: 465
|
||||
@@ -12,6 +13,7 @@ email_accounts:
|
||||
imap_port: 993
|
||||
username: "your_email@126.com"
|
||||
password: "your_auth_code"
|
||||
use_ssl: true
|
||||
smtp:
|
||||
server: "smtp.126.com"
|
||||
port: 465
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user