feat(email_service): Add dynamic email provider configuration support
- Import EMAIL_PROVIDER from config at runtime in unified functions to enable dynamic provider switching - Update unified_generate_email() to fetch current provider configuration on each call - Update unified_create_email() to fetch current provider configuration on each call - Update unified_get_verification_code() to fetch current provider configuration on each call - Update unified_fetch_emails() to fetch current provider configuration on each call - Update fallback comments to reflect support for both KYX and Cloud Mail systems - Allows email provider to be switched without restarting the application
This commit is contained in:
@@ -632,7 +632,10 @@ def unified_generate_email() -> str:
|
|||||||
Returns:
|
Returns:
|
||||||
str: 邮箱地址
|
str: 邮箱地址
|
||||||
"""
|
"""
|
||||||
if EMAIL_PROVIDER == "gptmail":
|
# 每次调用时重新获取配置,支持动态切换
|
||||||
|
from config import EMAIL_PROVIDER as current_provider
|
||||||
|
|
||||||
|
if current_provider == "gptmail":
|
||||||
# 生成随机前缀 + oaiteam 后缀,确保不重复
|
# 生成随机前缀 + oaiteam 后缀,确保不重复
|
||||||
random_str = ''.join(random.choices(string.ascii_lowercase + string.digits, k=8))
|
random_str = ''.join(random.choices(string.ascii_lowercase + string.digits, k=8))
|
||||||
prefix = f"{random_str}-oaiteam"
|
prefix = f"{random_str}-oaiteam"
|
||||||
@@ -642,7 +645,7 @@ def unified_generate_email() -> str:
|
|||||||
return email
|
return email
|
||||||
log.warning(f"GPTMail 生成失败,回退到 KYX: {error}")
|
log.warning(f"GPTMail 生成失败,回退到 KYX: {error}")
|
||||||
|
|
||||||
# 默认使用 KYX 系统
|
# 默认使用 KYX / Cloud Mail 系统
|
||||||
return generate_random_email()
|
return generate_random_email()
|
||||||
|
|
||||||
|
|
||||||
@@ -652,7 +655,10 @@ def unified_create_email() -> tuple[str, str]:
|
|||||||
Returns:
|
Returns:
|
||||||
tuple: (email, password)
|
tuple: (email, password)
|
||||||
"""
|
"""
|
||||||
if EMAIL_PROVIDER == "gptmail":
|
# 每次调用时重新获取配置,支持动态切换
|
||||||
|
from config import EMAIL_PROVIDER as current_provider
|
||||||
|
|
||||||
|
if current_provider == "gptmail":
|
||||||
# 生成随机前缀 + oaiteam 后缀,确保不重复
|
# 生成随机前缀 + oaiteam 后缀,确保不重复
|
||||||
random_str = ''.join(random.choices(string.ascii_lowercase + string.digits, k=8))
|
random_str = ''.join(random.choices(string.ascii_lowercase + string.digits, k=8))
|
||||||
prefix = f"{random_str}-oaiteam"
|
prefix = f"{random_str}-oaiteam"
|
||||||
@@ -663,7 +669,7 @@ def unified_create_email() -> tuple[str, str]:
|
|||||||
return email, DEFAULT_PASSWORD
|
return email, DEFAULT_PASSWORD
|
||||||
log.warning(f"GPTMail 生成失败,回退到 KYX: {error}")
|
log.warning(f"GPTMail 生成失败,回退到 KYX: {error}")
|
||||||
|
|
||||||
# 默认使用 KYX 系统
|
# 默认使用 KYX / Cloud Mail 系统
|
||||||
email = generate_random_email()
|
email = generate_random_email()
|
||||||
success, msg = create_email_user(email, DEFAULT_PASSWORD)
|
success, msg = create_email_user(email, DEFAULT_PASSWORD)
|
||||||
if success or "已存在" in msg:
|
if success or "已存在" in msg:
|
||||||
@@ -682,10 +688,13 @@ def unified_get_verification_code(email: str, max_retries: int = None, interval:
|
|||||||
Returns:
|
Returns:
|
||||||
tuple: (code, error, email_time) - 验证码、错误信息、邮件时间
|
tuple: (code, error, email_time) - 验证码、错误信息、邮件时间
|
||||||
"""
|
"""
|
||||||
if EMAIL_PROVIDER == "gptmail":
|
# 每次调用时重新获取配置,支持动态切换
|
||||||
|
from config import EMAIL_PROVIDER as current_provider
|
||||||
|
|
||||||
|
if current_provider == "gptmail":
|
||||||
return gptmail_service.get_verification_code(email, max_retries, interval)
|
return gptmail_service.get_verification_code(email, max_retries, interval)
|
||||||
|
|
||||||
# 默认使用 KYX 系统
|
# 默认使用 KYX / Cloud Mail 系统
|
||||||
return get_verification_code(email, max_retries, interval)
|
return get_verification_code(email, max_retries, interval)
|
||||||
|
|
||||||
|
|
||||||
@@ -698,9 +707,12 @@ def unified_fetch_emails(email: str) -> list:
|
|||||||
Returns:
|
Returns:
|
||||||
list: 邮件列表
|
list: 邮件列表
|
||||||
"""
|
"""
|
||||||
if EMAIL_PROVIDER == "gptmail":
|
# 每次调用时重新获取配置,支持动态切换
|
||||||
|
from config import EMAIL_PROVIDER as current_provider
|
||||||
|
|
||||||
|
if current_provider == "gptmail":
|
||||||
emails, error = gptmail_service.get_emails(email)
|
emails, error = gptmail_service.get_emails(email)
|
||||||
return emails
|
return emails
|
||||||
|
|
||||||
# 默认使用 KYX 系统
|
# 默认使用 KYX / Cloud Mail 系统
|
||||||
return fetch_email_content(email)
|
return fetch_email_content(email)
|
||||||
|
|||||||
Reference in New Issue
Block a user