81 lines
2.7 KiB
Python
81 lines
2.7 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import requests
|
|
import json
|
|
from pprint import pprint
|
|
|
|
def get_all_domains():
|
|
"""获取所有域名"""
|
|
response = requests.get("http://localhost:5000/api/domains")
|
|
if response.status_code == 200:
|
|
return response.json().get('domains', [])
|
|
return []
|
|
|
|
def get_all_mailboxes():
|
|
"""获取所有邮箱"""
|
|
response = requests.get("http://localhost:5000/api/mailboxes")
|
|
if response.status_code == 200:
|
|
return response.json().get('mailboxes', [])
|
|
return []
|
|
|
|
def get_mailbox_emails(mailbox_id):
|
|
"""获取指定邮箱的所有邮件"""
|
|
response = requests.get(f"http://localhost:5000/api/mailboxes/{mailbox_id}/emails")
|
|
print(f"API响应状态码: {response.status_code}")
|
|
if response.status_code == 200:
|
|
return response.json().get('emails', [])
|
|
return []
|
|
|
|
def get_email_detail(email_id):
|
|
"""获取指定邮件的详细信息"""
|
|
response = requests.get(f"http://localhost:5000/api/emails/{email_id}")
|
|
if response.status_code == 200:
|
|
return response.json().get('email', {})
|
|
return {}
|
|
|
|
def main():
|
|
# 获取所有域名
|
|
print("获取所有域名...")
|
|
domains = get_all_domains()
|
|
print(f"找到 {len(domains)} 个域名:")
|
|
for domain in domains:
|
|
print(f" - {domain.get('name')} (ID: {domain.get('id')})")
|
|
|
|
# 获取所有邮箱
|
|
print("\n获取所有邮箱...")
|
|
mailboxes = get_all_mailboxes()
|
|
print(f"找到 {len(mailboxes)} 个邮箱:")
|
|
for mailbox in mailboxes:
|
|
print(f" - {mailbox.get('full_address')} (ID: {mailbox.get('id')})")
|
|
|
|
# 遍历所有邮箱获取邮件
|
|
for mailbox in mailboxes:
|
|
mailbox_id = mailbox.get('id')
|
|
mailbox_address = mailbox.get('full_address')
|
|
print(f"\n获取邮箱 {mailbox_address} (ID: {mailbox_id}) 的邮件...")
|
|
|
|
emails = get_mailbox_emails(mailbox_id)
|
|
print(f"找到 {len(emails)} 封邮件")
|
|
|
|
for index, email in enumerate(emails, 1):
|
|
email_id = email.get('id')
|
|
print(f"\n--- 邮件 {index} (ID: {email_id}) ---")
|
|
print(f"主题: {email.get('subject')}")
|
|
print(f"发件人: {email.get('sender')}")
|
|
print(f"接收时间: {email.get('received_at')}")
|
|
|
|
print("\n完整邮件信息:")
|
|
# 打印所有字段
|
|
for key, value in email.items():
|
|
print(f" - {key}: {value}")
|
|
|
|
# 获取邮件验证码相关字段
|
|
verification_code = email.get('verification_code')
|
|
if verification_code:
|
|
print(f"\n提取到的验证码: {verification_code}")
|
|
|
|
print("-" * 50)
|
|
|
|
if __name__ == "__main__":
|
|
main() |