文件
skills/email-verification/SKILL.md

510 行
15 KiB
Markdown
原始文件 Blame 文件历史

此文件含有模棱两可的 Unicode 字符
此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。
---
name: email-verification
description: 邮箱验证码获取服务 - 支持临时邮箱API获取验证码、验证链接和完整邮件内容
domain: utilities
version: 1.0.0
tags: [email, verification, code, outlook, temp-mail, api]
triggers:
keywords:
primary: [邮箱验证码, 验证码获取, email code, verification code, 邮件验证]
secondary: [临时邮箱, temp mail, outlook验证码, email verification, 获取验证码]
context_boost: [注册, register, 验证, verify, 邮箱, email]
priority: high
---
# Email Verification Service
临时邮箱验证码获取服务,用于自动化注册流程中获取邮箱验证码。
## API 配置
```
Base URL: https://one.hao.work/api/mail
API Key: 2b358a68a8de4403b29949bf7b3a46f0
```
## 认证方式
所有请求需要在 Header 中添加:
```bash
-H "Authorization: Bearer 2b358a68a8de4403b29949bf7b3a46f0"
```
---
## API 端点
### 1. 获取可用邮箱账户列表
```bash
curl -X GET \
'https://one.hao.work/api/mail/accounts' \
-H 'accept: application/json' \
-H 'Authorization: Bearer 2b358a68a8de4403b29949bf7b3a46f0'
```
**响应示例:**
```json
{
"data": [
{
"id": 465,
"email": "tertia1948tasha315ne@outlook.com",
"password": "Kyle4714",
"status": 1,
"statusText": "登录成功IMAP",
"lastCheck": "2026-03-02T07:39:14Z",
"lastFrom": "Binance <do_not_reply@mgdirectmail.binance.com>",
"loginOk": true
}
]
}
```
**字段说明:**
| 字段 | 类型 | 说明 |
|------|------|------|
| id | integer | 账户ID |
| email | string | 邮箱地址 |
| password | string | 邮箱密码 |
| status | integer | 状态码 (1=正常) |
| statusText | string | 状态描述 |
| lastCheck | string | 最后检查时间 |
| lastFrom | string | 最后收到邮件的发件人 |
| loginOk | boolean | 登录是否成功 |
---
### 2. 获取最新邮件(推荐)
一站式获取最新邮件,包含验证码、链接和完整内容。
```bash
curl -X POST \
'https://one.hao.work/api/mail/all-in-one' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer 2b358a68a8de4403b29949bf7b3a46f0' \
-d '{
"email": "faye1989arlene1029@outlook.com",
"useApiOnly": true,
"timeoutSeconds": 180,
"recentWithinMinutes": 10
}'
```
**参数说明:**
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| email | string | 是 | 邮箱地址 |
| useApiOnly | boolean | 否 | 是否仅使用API获取,默认 true |
| timeoutSeconds | integer | 否 | 超时时间(秒),默认 180 |
| recentWithinMinutes | integer | 否 | 只获取最近 N 分钟内的邮件,避免误判旧邮件 |
**响应示例:**
```json
{
"success": true,
"email": "faye1989arlene1029@outlook.com",
"message": {
"from": "noreply@binance.com",
"to": "faye1989arlene1029@outlook.com",
"subject": "Binance 验证码",
"date": "2026-03-02T01:30:00Z",
"text": "您的验证码是123456。有效期10分钟。",
"html": "<html><body>您的验证码是:<b>123456</b>。有效期10分钟。</body></html>",
"verification": {
"code": "123456",
"link": "https://www.binance.com/verify?token=abc123xyz",
"type": "registration"
}
},
"timestamp": 1772441437665
}
```
---
## 使用流程
### 标准流程
```
┌─────────────────────────────────────────────────────────────┐
│ 邮箱验证码获取流程 │
│ │
│ ┌─────────────┐ │
│ │ 准备邮箱地址 │ │
│ └──────┬──────┘ │
│ │ │
│ ▼ │
│ ┌─────────────┐ │
│ │ 发送验证请求 │ POST /api/mail/all-in-one │
│ │ (注册/登录) │ │
│ └──────┬──────┘ │
│ │ │
│ ▼ │
│ ┌─────────────┐ │
│ │ 等待邮件到达 │ timeoutSeconds: 180 │
│ │ (最长3分钟) │ │
│ └──────┬──────┘ │
│ │ │
│ ▼ │
│ ┌─────────────┐ │
│ │ 获取邮件内容 │ text + html + 验证码 + 链接 │
│ └──────┬──────┘ │
│ │ │
│ ▼ │
│ ┌─────────────┐ │
│ │ 提取验证码 │ 自动识别 4-8 位数字验证码 │
│ └──────┬──────┘ │
│ │ │
│ ▼ │
│ ┌─────────────┐ │
│ │ 完成验证 │ 填入验证码或点击链接 │
│ └─────────────┘ │
└─────────────────────────────────────────────────────────────┘
```
---
## 自动化脚本示例
### Python 示例
```python
import requests
import time
import re
class EmailVerificationService:
def __init__(self, api_key="2b358a68a8de4403b29949bf7b3a46f0"):
self.base_url = "https://one.hao.work/api/mail"
self.headers = {
"accept": "application/json",
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
def get_accounts(self):
"""获取可用邮箱账户列表"""
response = requests.get(
f"{self.base_url}/accounts",
headers=self.headers
)
return response.json()
def get_latest_email(self, email, timeout=180, recent_minutes=None):
"""获取最新邮件"""
payload = {
"email": email,
"useApiOnly": True,
"timeoutSeconds": timeout
}
if recent_minutes:
payload["recentWithinMinutes"] = recent_minutes
response = requests.post(
f"{self.base_url}/all-in-one",
headers=self.headers,
json=payload
)
return response.json()
def extract_verification_code(self, email_content):
"""从邮件内容中提取验证码"""
# 常见验证码模式
patterns = [
r'验证码[是为::\s]*(\d{4,8})',
r'verification code[是为::\s]*(\d{4,8})',
r'code[是为::\s]*(\d{4,8})',
r'\b(\d{6})\b', # 6位数字
r'\b(\d{4})\b', # 4位数字
]
text = email_content.get('text', '') or email_content.get('html', '')
for pattern in patterns:
match = re.search(pattern, text, re.IGNORECASE)
if match:
return match.group(1)
return None
def wait_for_verification_code(self, email, timeout=180, interval=5, recent_minutes=10):
"""等待并获取验证码"""
start_time = time.time()
while time.time() - start_time < timeout:
result = self.get_latest_email(email, timeout=interval, recent_minutes=recent_minutes)
if result.get('success') and result.get('message'):
message = result['message']
# 优先使用自动识别的验证码
if message.get('verification', {}).get('code'):
return {
'code': message['verification']['code'],
'link': message['verification'].get('link'),
'full_message': message
}
# 手动提取验证码
code = self.extract_verification_code(message)
if code:
return {
'code': code,
'link': message.get('verification', {}).get('link'),
'full_message': message
}
time.sleep(interval)
return None
# 使用示例
if __name__ == "__main__":
service = EmailVerificationService()
# 获取验证码
result = service.wait_for_verification_code(
"faye1989arlene1029@outlook.com",
timeout=180
)
if result:
print(f"验证码: {result['code']}")
print(f"验证链接: {result['link']}")
print(f"完整邮件: {result['full_message']}")
```
### Bash/cURL 示例
```bash
#!/bin/bash
API_KEY="2b358a68a8de4403b29949bf7b3a46f0"
BASE_URL="https://one.hao.work/api/mail"
# 获取验证码
get_verification_code() {
local email=$1
local timeout=${2:-180}
curl -X POST \
"${BASE_URL}/all-in-one" \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H "X-API-Key: ${API_KEY}" \
-d "{
\"email\": \"${email}\",
\"useApiOnly\": true,
\"timeoutSeconds\": ${timeout}
}"
}
# 使用示例
get_verification_code "faye1989arlene1029@outlook.com" 180
```
---
## 验证码提取规则
### 常见验证码格式
| 格式 | 示例 | 正则表达式 |
|------|------|-----------|
| 4位数字 | 1234 | `\b(\d{4})\b` |
| 6位数字 | 123456 | `\b(\d{6})\b` |
| 带前缀 | 验证码123456 | `验证码[是为::\s]*(\d{4,8})` |
| 英文前缀 | Code: 123456 | `code[是为::\s]*(\d{4,8})` |
### 支持的邮件类型
- Outlook.com
- Hotmail.com
- Gmail (需要配置)
- 自定义域名邮箱
---
## 应用场景
### 1. 自动化注册流程
```python
# 1. 填写注册表单
fill_registration_form(email, password)
# 2. 提交注册
submit_registration()
# 3. 等待并获取验证码
service = EmailVerificationService()
result = service.wait_for_verification_code(email)
# 4. 填入验证码
fill_verification_code(result['code'])
# 5. 完成注册
complete_registration()
```
### 2. 批量账号注册
```python
accounts = [
"user1@outlook.com",
"user2@outlook.com",
"user3@outlook.com"
]
service = EmailVerificationService()
for email in accounts:
# 注册账号
register_account(email)
# 获取验证码
result = service.wait_for_verification_code(email)
if result:
verify_account(email, result['code'])
print(f"{email} 注册成功")
else:
print(f"{email} 获取验证码失败")
```
### 3. 验证链接提取
```python
result = service.wait_for_verification_code(email)
if result and result.get('link'):
# 方式1: 直接访问链接
requests.get(result['link'])
# 方式2: 提取链接中的token
import urllib.parse
parsed = urllib.parse.urlparse(result['link'])
token = urllib.parse.parse_qs(parsed.query).get('token', [None])[0]
```
---
## 错误处理
### 常见错误码
| 状态码 | 说明 | 解决方案 |
|--------|------|---------|
| 401 | API Key 无效 | 检查 X-API-Key header |
| 404 | 邮箱不存在 | 确认邮箱地址正确 |
| 408 | 获取超时 | 增加 timeoutSeconds |
| 429 | 请求过于频繁 | 降低请求频率 |
| 500 | 服务器错误 | 稍后重试 |
### 重试机制
```python
def get_code_with_retry(email, max_retries=3):
service = EmailVerificationService()
for attempt in range(max_retries):
try:
result = service.wait_for_verification_code(email)
if result:
return result
except Exception as e:
print(f"尝试 {attempt + 1} 失败: {e}")
time.sleep(5)
return None
```
---
## 注意事项
1. **超时设置** - 默认 180 秒,根据邮件到达时间调整
2. **请求频率** - 避免过于频繁的请求,建议间隔 5 秒以上
3. **验证码有效期** - 通常 10-15 分钟,尽快使用
4. **邮件延迟** - 某些服务邮件可能有延迟,适当增加超时
5. **并发限制** - 同一邮箱同时只能有一个等待请求
---
## 与其他 Skill 集成
### 配合 Binance 注册
```python
# 在 Binance 注册流程中使用
from binance_registration import BinanceRegistration
from email_verification import EmailVerificationService
binance = BinanceRegistration()
email_service = EmailVerificationService()
# 1. 发送注册请求
email = "user@outlook.com"
binance.request_verification_code(email)
# 2. 获取验证码
result = email_service.wait_for_verification_code(email)
code = result['code']
# 3. 完成注册
binance.complete_registration(email, password, code)
```
---
## API 响应字段说明
### 完整响应结构
```json
{
"success": true,
"email": "user@outlook.com",
"message": {
"from": "sender@example.com",
"to": "user@outlook.com",
"subject": "邮件主题",
"date": "2026-03-02T01:30:00Z",
"text": "纯文本内容",
"html": "HTML内容",
"verification": {
"code": "123456",
"link": "https://example.com/verify?token=xxx",
"type": "registration|login|reset_password"
}
},
"timestamp": 1772441437665
}
```
### 字段说明
| 字段 | 类型 | 说明 |
|------|------|------|
| success | boolean | 请求是否成功 |
| email | string | 邮箱地址 |
| message.from | string | 发件人地址 |
| message.to | string | 收件人地址 |
| message.subject | string | 邮件主题 |
| message.date | string | 邮件日期时间 (ISO 8601) |
| message.text | string | 纯文本内容 |
| message.html | string | HTML 内容 |
| message.verification.code | string | 自动识别的验证码 |
| message.verification.link | string | 验证链接 |
| message.verification.type | string | 验证类型 |
| timestamp | integer | 响应时间戳 (毫秒) |