feat: support custom DuckMail domains
This commit is contained in:
@@ -398,9 +398,10 @@ class MoeMailProvider(MailProvider):
|
||||
# ==================== DuckMail ====================
|
||||
|
||||
class DuckMailProvider(MailProvider):
|
||||
def __init__(self, api_base: str = "https://api.duckmail.sbs", bearer_token: str = ""):
|
||||
def __init__(self, api_base: str = "https://api.duckmail.sbs", bearer_token: str = "", domain: str = ""):
|
||||
self.api_base = api_base.rstrip("/")
|
||||
self.bearer_token = bearer_token
|
||||
self.domain = str(domain).strip()
|
||||
|
||||
def _auth_headers(self, token: str = "") -> Dict[str, str]:
|
||||
h: Dict[str, str] = {"Accept": "application/json"}
|
||||
@@ -419,6 +420,8 @@ class DuckMailProvider(MailProvider):
|
||||
headers["Authorization"] = f"Bearer {self.bearer_token}"
|
||||
|
||||
try:
|
||||
domain = self.domain
|
||||
if not domain:
|
||||
domains_resp = session.get(f"{self.api_base}/domains", headers={"Accept": "application/json"}, timeout=15, verify=False)
|
||||
if domains_resp.status_code != 200:
|
||||
return "", ""
|
||||
@@ -793,6 +796,7 @@ def create_provider_by_name(provider_type: str, mail_cfg: Dict[str, Any]) -> Mai
|
||||
return DuckMailProvider(
|
||||
api_base=api_base or "https://api.duckmail.sbs",
|
||||
bearer_token=str(mail_cfg.get("bearer_token", "")).strip(),
|
||||
domain=str(mail_cfg.get("domain", "")).strip(),
|
||||
)
|
||||
elif provider_type == "cloudflare_temp_email":
|
||||
return CloudflareTempEmailProvider(
|
||||
|
||||
@@ -632,6 +632,11 @@
|
||||
<input type="text" data-key="api_base" placeholder="https://api.duckmail.sbs" autocomplete="off"
|
||||
spellcheck="false" />
|
||||
</div>
|
||||
<div class="config-field">
|
||||
<label>分配域名</label>
|
||||
<input type="text" data-key="domain" placeholder="example.com" autocomplete="off"
|
||||
spellcheck="false" />
|
||||
</div>
|
||||
<div class="config-field">
|
||||
<label>Bearer Token</label>
|
||||
<input type="password" data-key="bearer_token" placeholder="DuckMail Bearer Token"
|
||||
|
||||
Reference in New Issue
Block a user