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
This commit is contained in:
2026-01-30 16:15:17 +08:00
parent b50ad199de
commit ae86ca42df

View File

@@ -442,14 +442,17 @@ def create_email_user(email: str, password: str = None, role_name: str = None) -
Returns: Returns:
tuple: (success, message) tuple: (success, message)
""" """
# 每次调用时重新获取配置,支持动态切换
from config import EMAIL_API_AUTH as current_auth, EMAIL_ROLE as current_role
if password is None: if password is None:
password = DEFAULT_PASSWORD password = DEFAULT_PASSWORD
if role_name is None: if role_name is None:
role_name = EMAIL_ROLE role_name = current_role
url = f"{get_cloudmail_api_base()}/addUser" url = f"{get_cloudmail_api_base()}/addUser"
headers = { headers = {
"Authorization": EMAIL_API_AUTH, "Authorization": current_auth,
"Content-Type": "application/json" "Content-Type": "application/json"
} }
payload = { payload = {
@@ -485,9 +488,12 @@ def get_verification_code(email: str, max_retries: int = None, interval: int = N
Returns: Returns:
tuple: (code, error, email_time) - 验证码、错误信息、邮件时间 tuple: (code, error, email_time) - 验证码、错误信息、邮件时间
""" """
# 每次调用时重新获取配置,支持动态切换
from config import EMAIL_API_AUTH as current_auth
url = f"{get_cloudmail_api_base()}/emailList" url = f"{get_cloudmail_api_base()}/emailList"
headers = { headers = {
"Authorization": EMAIL_API_AUTH, "Authorization": current_auth,
"Content-Type": "application/json" "Content-Type": "application/json"
} }
payload = {"toEmail": email} payload = {"toEmail": email}
@@ -566,9 +572,12 @@ def fetch_email_content(email: str) -> list:
Returns: Returns:
list: 邮件列表 list: 邮件列表
""" """
# 每次调用时重新获取配置,支持动态切换
from config import EMAIL_API_AUTH as current_auth
url = f"{get_cloudmail_api_base()}/emailList" url = f"{get_cloudmail_api_base()}/emailList"
headers = { headers = {
"Authorization": EMAIL_API_AUTH, "Authorization": current_auth,
"Content-Type": "application/json" "Content-Type": "application/json"
} }
payload = {"toEmail": email} payload = {"toEmail": email}