From ae86ca42df288c97b0a742c14c27229332a9fb7f Mon Sep 17 00:00:00 2001 From: kyx236 Date: Fri, 30 Jan 2026 16:15:17 +0800 Subject: [PATCH] feat(email_service): Support dynamic email configuration reloading - Import EMAIL_API_AUTH and EMAIL_ROLE from config module on each function call - Update create_email_user() to use dynamically loaded current_auth and current_role - Update get_verification_code() to use dynamically loaded current_auth - Update fetch_email_content() to use dynamically loaded current_auth - Enable runtime configuration switching without service restart --- email_service.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/email_service.py b/email_service.py index 3445ddb..a02a305 100644 --- a/email_service.py +++ b/email_service.py @@ -442,14 +442,17 @@ def create_email_user(email: str, password: str = None, role_name: str = None) - Returns: tuple: (success, message) """ + # 每次调用时重新获取配置,支持动态切换 + from config import EMAIL_API_AUTH as current_auth, EMAIL_ROLE as current_role + if password is None: password = DEFAULT_PASSWORD if role_name is None: - role_name = EMAIL_ROLE + role_name = current_role url = f"{get_cloudmail_api_base()}/addUser" headers = { - "Authorization": EMAIL_API_AUTH, + "Authorization": current_auth, "Content-Type": "application/json" } payload = { @@ -485,9 +488,12 @@ def get_verification_code(email: str, max_retries: int = None, interval: int = N Returns: tuple: (code, error, email_time) - 验证码、错误信息、邮件时间 """ + # 每次调用时重新获取配置,支持动态切换 + from config import EMAIL_API_AUTH as current_auth + url = f"{get_cloudmail_api_base()}/emailList" headers = { - "Authorization": EMAIL_API_AUTH, + "Authorization": current_auth, "Content-Type": "application/json" } payload = {"toEmail": email} @@ -566,9 +572,12 @@ def fetch_email_content(email: str) -> list: Returns: list: 邮件列表 """ + # 每次调用时重新获取配置,支持动态切换 + from config import EMAIL_API_AUTH as current_auth + url = f"{get_cloudmail_api_base()}/emailList" headers = { - "Authorization": EMAIL_API_AUTH, + "Authorization": current_auth, "Content-Type": "application/json" } payload = {"toEmail": email}