feat(config): load mail provider api keys from env

This commit is contained in:
Logic
2026-03-21 15:41:02 +08:00
parent cf20b9acc6
commit 624ca1e1cc
3 changed files with 24 additions and 7 deletions

View File

@@ -5,16 +5,26 @@ from abc import ABC, abstractmethod
import httpx
try:
from .config import settings
except ImportError: # pragma: no cover - allow direct script execution from source tree
from config import settings
# vmail.dev config
VMAIL_BASE = "https://vmail.dev/api/v1"
VMAIL_API_KEY = "vmail_UCjaCMZghzKaH5KrRlKXyxkrCO7ZNesV"
# mail.tm config
MAILTM_BASE = "https://api.mail.tm"
# yyds mail config
YYDS_BASE = "https://maliapi.215.im"
YYDS_API_KEY = "AC-4a23c58b8f84c19a27ef509e"
def _require_api_key(provider: str, env_name: str, value: str) -> str:
api_key = value.strip()
if api_key:
return api_key
raise RuntimeError(f"{provider} requires {env_name} to be set in the environment or .env")
class BaseMailClient(ABC):
@@ -39,7 +49,7 @@ class VMailClient(BaseMailClient):
"""vmail.dev temporary email client."""
def __init__(self):
self.api_key = VMAIL_API_KEY
self.api_key = _require_api_key("vmail.dev", "VMAIL_API_KEY", settings.vmail_api_key)
self.headers = {"X-API-Key": self.api_key}
self.base = VMAIL_BASE
@@ -249,7 +259,7 @@ class YYDSMailClient(BaseMailClient):
"""YYDS Mail temporary email client (maliapi.215.im)."""
def __init__(self):
self.api_key = YYDS_API_KEY
self.api_key = _require_api_key("YYDS Mail", "YYDS_API_KEY", settings.yyds_api_key)
self.headers = {"X-API-Key": self.api_key}
self.base = YYDS_BASE