Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/services/tempmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
from typing import Optional, Dict, Any, List
import json
import os

from curl_cffi import requests as cffi_requests

Expand Down Expand Up @@ -48,6 +49,12 @@ def __init__(self, config: Dict[str, Any] = None, name: str = None):

self.config = {**default_config, **(config or {})}

# ←←← 最终优化:API Key 完全可选(付费/免费自动切换)↓↓↓
self.api_key = self.config.get("api_key") or os.getenv("TEMPMail_API_KEY")
if self.api_key:
logger.info(f"✅ Tempmail.lol Plus/Ultra 已加载 API Key: {self.api_key[:30]}...")
# 没 Key 时不打印任何警告,直接走免费模式(符合你的需求)

# 创建 HTTP 客户端
http_config = RequestConfig(
timeout=self.config["timeout"],
Expand Down Expand Up @@ -83,6 +90,7 @@ def create_email(self, config: Dict[str, Any] = None) -> Dict[str, Any]:
headers={
"Accept": "application/json",
"Content-Type": "application/json",
**({"Authorization": f"Bearer {self.api_key}"} if self.api_key else {}),
},
json={}
)
Expand Down Expand Up @@ -163,7 +171,10 @@ def get_verification_code(
response = self.http_client.get(
f"{self.config['base_url']}/inbox",
params={"token": token},
headers={"Accept": "application/json"}
headers={
"Accept": "application/json",
**({"Authorization": f"Bearer {self.api_key}"} if self.api_key else {}),
}
)

if response.status_code != 200:
Expand Down
Loading