fix(mail): normalize provider selection

This commit is contained in:
Logic
2026-03-21 16:45:43 +08:00
parent 624ca1e1cc
commit ba02799b18

View File

@@ -356,14 +356,20 @@ class YYDSMailClient(BaseMailClient):
raise TimeoutError(f"No OTP received within {timeout}s")
def get_mail_client(provider: str = "vmail") -> BaseMailClient:
def get_mail_client(provider: str | None = None) -> BaseMailClient:
"""Get mail client by provider name."""
if provider == "mailtm":
raw_provider = settings.mail_provider if provider is None else provider
normalized = (raw_provider or "").strip().lower()
if normalized == "vmail":
return VMailClient()
if normalized == "mailtm":
return MailTMClient()
if provider == "yyds":
if normalized == "yyds":
return YYDSMailClient()
return VMailClient() # default to vmail
# Default instance
MailClient = get_mail_client("vmail")
if not normalized:
raise ValueError("MAIL_PROVIDER is empty; expected one of: vmail, mailtm, yyds")
raise ValueError(
f"Unsupported MAIL_PROVIDER={raw_provider!r}; expected one of: vmail, mailtm, yyds"
)