Spaces:
Paused
Paused
feat: 首次配置后自动验证 CloudMail 连通性
Browse files- 配置保存后自动测试:登录 → 创建测试邮箱 → 删除
- 失败时提示具体哪个环节有问题
- reload cloudmail 模块确保读到新配置
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- src/autoteam/setup_wizard.py +52 -1
src/autoteam/setup_wizard.py
CHANGED
|
@@ -107,11 +107,62 @@ def check_and_setup(interactive: bool = True) -> bool:
|
|
| 107 |
|
| 108 |
print("\n配置已保存到 .env\n")
|
| 109 |
|
| 110 |
-
# 重新加载 config 模块
|
| 111 |
import importlib
|
| 112 |
|
| 113 |
import autoteam.config
|
| 114 |
|
| 115 |
importlib.reload(autoteam.config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
print("\n配置已保存到 .env\n")
|
| 109 |
|
| 110 |
+
# 重新加载 config 和依赖模块
|
| 111 |
import importlib
|
| 112 |
|
| 113 |
import autoteam.config
|
| 114 |
|
| 115 |
importlib.reload(autoteam.config)
|
| 116 |
+
try:
|
| 117 |
+
import autoteam.cloudmail
|
| 118 |
+
|
| 119 |
+
importlib.reload(autoteam.cloudmail)
|
| 120 |
+
except Exception:
|
| 121 |
+
pass
|
| 122 |
+
|
| 123 |
+
# 验证 CloudMail 配置
|
| 124 |
+
_verify_cloudmail()
|
| 125 |
|
| 126 |
return True
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def _verify_cloudmail():
|
| 130 |
+
"""验证 CloudMail 配置是否正确:登录 + 创建测试邮箱 + 删除"""
|
| 131 |
+
base_url = os.environ.get("CLOUDMAIL_BASE_URL", "")
|
| 132 |
+
email = os.environ.get("CLOUDMAIL_EMAIL", "")
|
| 133 |
+
password = os.environ.get("CLOUDMAIL_PASSWORD", "")
|
| 134 |
+
domain = os.environ.get("CLOUDMAIL_DOMAIN", "")
|
| 135 |
+
|
| 136 |
+
if not all([base_url, email, password, domain]):
|
| 137 |
+
return
|
| 138 |
+
|
| 139 |
+
print("验证 CloudMail 配置...")
|
| 140 |
+
|
| 141 |
+
try:
|
| 142 |
+
from autoteam.cloudmail import CloudMailClient
|
| 143 |
+
|
| 144 |
+
client = CloudMailClient()
|
| 145 |
+
client.login()
|
| 146 |
+
print(" [1/3] 登录成功")
|
| 147 |
+
except Exception as e:
|
| 148 |
+
print(f" [1/3] 登录失败: {e}")
|
| 149 |
+
print(" 请检查 CLOUDMAIL_BASE_URL、CLOUDMAIL_EMAIL、CLOUDMAIL_PASSWORD 是否正确")
|
| 150 |
+
return
|
| 151 |
+
|
| 152 |
+
test_account_id = None
|
| 153 |
+
try:
|
| 154 |
+
test_account_id, test_email = client.create_temp_email(prefix="autoteam-test")
|
| 155 |
+
print(f" [2/3] 创建测试邮箱成功: {test_email}")
|
| 156 |
+
except Exception as e:
|
| 157 |
+
print(f" [2/3] 创建邮箱失败: {e}")
|
| 158 |
+
print(" 请检查 CLOUDMAIL_DOMAIN 是否正确")
|
| 159 |
+
return
|
| 160 |
+
|
| 161 |
+
try:
|
| 162 |
+
if test_account_id:
|
| 163 |
+
client.delete_account(test_account_id)
|
| 164 |
+
print(" [3/3] 测试邮箱已清理")
|
| 165 |
+
except Exception as e:
|
| 166 |
+
print(f" [3/3] 清理测试邮箱失败: {e}(不影响使用)")
|
| 167 |
+
|
| 168 |
+
print(" CloudMail 配置验证通过\n")
|