所需权限: otp
POST
/api/v1/otp/send
通过邮件发送验证码。
Request Body
{
"email": "user@example.com",
"template": "login", // optional: login, signup, reset
"expires_in": 300, // optional: seconds (default: 300)
"code_length": 6 // optional: 4-8 (default: 6)
}
Response
{
"success": true,
"data": {
"session_id": "abc123...",
"email": "user@example.com",
"expires_at": "2026-01-10T12:05:00Z"
}
}
POST
/api/v1/otp/verify
验证验证码。
Request Body
{
"session_id": "abc123...",
"code": "123456"
}
Response (Success)
{
"success": true,
"data": {
"verified": true,
"email": "user@example.com"
}
}
Response (Failed)
{
"success": false,
"error": {
"code": "INVALID_CODE",
"message": "The verification code is invalid or expired."
}
}
POST
/api/v1/otp/resend
重新发送验证码。
Request Body
{
"session_id": "abc123..."
}
Response
{
"success": true,
"data": {
"session_id": "abc123...",
"expires_at": "2026-01-10T12:05:00Z"
}
}
GET
/api/v1/otp/status/{session_id}
查询OTP会话状态。
Response
{
"success": true,
"data": {
"session_id": "abc123...",
"email": "user@example.com",
"status": "pending", // pending, verified, expired
"attempts": 2,
"max_attempts": 5,
"expires_at": "2026-01-10T12:05:00Z"
}
}
使用示例
cURL
# 1. Send OTP
curl -X POST https://dev.mailpass.im/api/v1/otp/send \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"email": "user@example.com"}'
# 2. Verify OTP
curl -X POST https://dev.mailpass.im/api/v1/otp/verify \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"session_id": "abc123...", "code": "123456"}'
JavaScript (fetch)
// Send OTP
const response = await fetch('https://dev.mailpass.im/api/v1/otp/send', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({ email: 'user@example.com' })
});
const data = await response.json();