API文档

Mail Send API

便捷发送事务性邮件的API。支持单条即时发送和批量队列发送。

所需权限: mail

POST /api/v1/mail/send

即时发送单条邮件。通过用户的默认SMTP provider发送。

Request Body

{
  "to": "user@example.com",
  "subject": "Order Confirmation",
  "html": "<h1>Your order has been confirmed</h1>",
  "text": "Your order has been confirmed",
  "from_email": "support@yourdomain.com",
  "from_name": "Your App",
  "reply_to": "reply@yourdomain.com",
  "cc": ["cc@example.com"],
  "bcc": ["bcc@example.com"],
  "tags": ["order", "confirmation"],
  "metadata": {"order_id": "12345"}
}

Parameters

Field Type Required Description
tostringYes收件人邮箱
subjectstringYes邮件主题
htmlstringYes*HTML正文(*html或text必须提供其一)
textstringYes*纯文本正文
from_emailstringNo发件人邮箱(默认: SMTP provider设置)
from_namestringNo发件人名称
reply_tostringNo回复地址
ccarrayNo抄送邮箱列表
bccarrayNo密送邮箱列表
tagsarrayNo邮件标签(用于分类)
metadataobjectNo自定义元数据

Response

{
  "success": true,
  "data": {
    "message_id": "<abc123.1706600000@mailpass.im>",
    "status": "sent",
    "to": "user@example.com",
    "from": "support@yourdomain.com"
  }
}
POST /api/v1/mail/send-batch

将多条邮件添加到队列。最多支持100条,由Cron处理。

Request Body

{
  "messages": [
    {"to": "a@example.com", "subject": "Hello A", "html": "<p>Hi A</p>"},
    {"to": "b@example.com", "subject": "Hello B", "html": "<p>Hi B</p>"}
  ],
  "from_email": "support@yourdomain.com",
  "from_name": "Your App"
}

Response

{
  "success": true,
  "data": {
    "total": 2,
    "queued": 2,
    "failed": 0,
    "messages": [
      {"to": "a@example.com", "status": "queued", "queue_id": 101},
      {"to": "b@example.com", "status": "queued", "queue_id": 102}
    ]
  }
}
GET /api/v1/mail/status/{message_id}

查询已发送邮件的状态和跟踪事件。

Response

{
  "success": true,
  "data": {
    "message": {
      "message_id": "<abc123@mailpass.im>",
      "from_email": "support@yourdomain.com",
      "to_email": "user@example.com",
      "subject": "Order Confirmation",
      "status": "sent",
      "error_message": null,
      "sent_at": "2026-01-30T12:00:00",
      "created_at": "2026-01-30T12:00:00"
    },
    "events": [
      {
        "event_type": "open",
        "ip_address": "192.168.1.1",
        "user_agent": "Mozilla/5.0...",
        "created_at": "2026-01-30T12:05:00"
      }
    ]
  }
}

Error Codes

Code HTTP Description
VALIDATION_ERROR400缺少必填字段或邮箱无效
NO_SMTP_PROVIDER422未设置默认SMTP provider
SEND_LIMIT_EXCEEDED429超出SMTP provider每日/每小时发送限制
SEND_FAILED500邮件发送失败

使用示例

cURL

# Single send
curl -X POST https://dev.mailpass.im/api/v1/mail/send \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "user@example.com",
    "subject": "Hello",
    "html": "<p>Hello World</p>"
  }'

# Batch send
curl -X POST https://dev.mailpass.im/api/v1/mail/send-batch \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {"to": "a@example.com", "subject": "Hi A", "html": "<p>Hello A</p>"},
      {"to": "b@example.com", "subject": "Hi B", "html": "<p>Hello B</p>"}
    ],
    "from_email": "support@yourdomain.com"
  }'

# Check status
curl https://dev.mailpass.im/api/v1/mail/status/MESSAGE_ID \
  -H "Authorization: Bearer YOUR_API_KEY"

JavaScript (fetch)

// Single send
const response = await fetch('https://dev.mailpass.im/api/v1/mail/send', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    to: 'user@example.com',
    subject: 'Hello',
    html: '<p>Hello World</p>'
  })
});
const data = await response.json();
console.log(data.data.message_id);

PHP SDK

$client = new MailPass\Client('mp_live_YOUR_KEY');

// Single send
$result = $client->mail->send([
    'to' => 'user@example.com',
    'subject' => 'Hello',
    'html' => '<p>Hello World</p>',
]);
echo $result['data']['message_id'];

需要设置SMTP Provider

使用Mail Send API前,需先在仪表盘 > SMTP设置中添加SMTP provider并设为默认。支持MailPass自有SMTP、Amazon SES、SendGrid、Mailgun等。

我们使用 Cookie

我们使用 cookie 来改善您的体验。您可以选择允许哪些 cookie 类别。 了解更多