初始化提交,包含完整的邮件系统代码
This commit is contained in:
80
create_test_domain.py
Normal file
80
create_test_domain.py
Normal file
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
||||
# 基础URL
|
||||
BASE_URL = "http://localhost:5000/api"
|
||||
|
||||
def create_domain(name, description):
|
||||
"""创建一个新域名"""
|
||||
print(f"创建域名: {name}")
|
||||
url = f"{BASE_URL}/domains"
|
||||
data = {
|
||||
"name": name,
|
||||
"description": description
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(url, json=data)
|
||||
print(f"状态码: {response.status_code}")
|
||||
print(f"响应内容: {response.text}")
|
||||
response.raise_for_status()
|
||||
result = response.json()
|
||||
print(f"域名创建成功: {result}")
|
||||
return result.get("domain", {})
|
||||
except Exception as e:
|
||||
print(f"域名创建失败: {str(e)}")
|
||||
return None
|
||||
|
||||
def create_mailbox(domain_id, address, description=""):
|
||||
"""在指定域名下创建邮箱"""
|
||||
print(f"在域 {domain_id} 下创建邮箱: {address}")
|
||||
url = f"{BASE_URL}/mailboxes"
|
||||
data = {
|
||||
"domain_id": domain_id,
|
||||
"address": address,
|
||||
"description": description
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(url, json=data)
|
||||
print(f"状态码: {response.status_code}")
|
||||
print(f"响应内容: {response.text}")
|
||||
response.raise_for_status()
|
||||
result = response.json()
|
||||
print(f"邮箱创建成功: {result}")
|
||||
return result.get("mailbox", {})
|
||||
except Exception as e:
|
||||
print(f"邮箱创建失败: {str(e)}")
|
||||
return None
|
||||
|
||||
def main():
|
||||
# 检查API状态
|
||||
try:
|
||||
status_response = requests.get(f"{BASE_URL}/status")
|
||||
print(f"API状态: {status_response.status_code}")
|
||||
print(f"API响应: {status_response.text[:200]}...")
|
||||
except Exception as e:
|
||||
print(f"API状态检查失败: {str(e)}")
|
||||
|
||||
# 创建测试域名 nosqli.com
|
||||
domain = create_domain("nosqli.com", "测试域名")
|
||||
if not domain:
|
||||
print("无法继续,域名创建失败")
|
||||
return
|
||||
|
||||
# 获取域名ID
|
||||
domain_id = domain.get("id")
|
||||
|
||||
# 创建测试邮箱 testaa@nosqli.com
|
||||
mailbox = create_mailbox(domain_id, "testaa", "测试用户")
|
||||
|
||||
print("\n测试环境准备完成:")
|
||||
print(f"- 域名: nosqli.com (ID: {domain_id})")
|
||||
if mailbox:
|
||||
print(f"- 邮箱: testaa@nosqli.com (ID: {mailbox.get('id')})")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user