跳到正文

API

发送电子邮件

单封邮件、附件、定时发送、幂等性、批量发送、跟踪和统计信息。

发送一封邮件

POST /api/v1/emails,可使用任意密钥(sending_access 即可)。

cURL

curl https://mail.example.com/api/v1/emails \
  -H "Authorization: Bearer $VOAARO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "Acme <invoices@example.com>",
    "to": ["client@example.org"],
    "cc": ["accounting@example.org"],
    "reply_to": "support@example.com",
    "subject": "Your invoice F-2026-042",
    "html": "<p>Hello,</p><p>Your invoice is attached.</p>",
    "text": "Hello, your invoice is attached.",
    "tags": [{"name": "category", "value": "invoice"}],
    "headers": {"X-Entity-Ref-ID": "F-2026-042"}
  }'

Node / Bun

const { data, error } = await voaaro.emails.send({
  from: "Acme <invoices@example.com>",
  to: ["client@example.org"],
  cc: ["accounting@example.org"],
  replyTo: "support@example.com",
  subject: "Your invoice F-2026-042",
  html: "<p>Hello,</p><p>Your invoice is attached.</p>",
  text: "Hello, your invoice is attached.",
  tags: [{ name: "category", value: "invoice" }],
  headers: { "X-Entity-Ref-ID": "F-2026-042" },
})
if (error) throw new Error(`${error.name}: ${error.message}`)

Python

email = voaaro.Emails.send({
    "from": "Acme <invoices@example.com>",
    "to": ["client@example.org"],
    "cc": ["accounting@example.org"],
    "reply_to": "support@example.com",
    "subject": "Your invoice F-2026-042",
    "html": "<p>Hello,</p><p>Your invoice is attached.</p>",
    "text": "Hello, your invoice is attached.",
    "tags": [{"name": "category", "value": "invoice"}],
    "headers": {"X-Entity-Ref-ID": "F-2026-042"},
})

PHP

$email = $voaaro->emails->send([
    'from' => 'Acme <invoices@example.com>',
    'to' => ['client@example.org'],
    'cc' => ['accounting@example.org'],
    'replyTo' => 'support@example.com',
    'subject' => 'Your invoice F-2026-042',
    'html' => '<p>Hello,</p><p>Your invoice is attached.</p>',
    'text' => 'Hello, your invoice is attached.',
    'tags' => [['name' => 'category', 'value' => 'invoice']],
    'headers' => ['X-Entity-Ref-ID' => 'F-2026-042'],
]);

Go

sent, err := client.Emails.Send(&voaaro.SendEmailRequest{
	From:    "Acme <invoices@example.com>",
	To:      []string{"client@example.org"},
	Cc:      []string{"accounting@example.org"},
	ReplyTo: "support@example.com",
	Subject: "Your invoice F-2026-042",
	Html:    "<p>Hello,</p><p>Your invoice is attached.</p>",
	Text:    "Hello, your invoice is attached.",
	Tags:    []voaaro.Tag{{Name: "category", Value: "invoice"}},
	Headers: map[string]string{"X-Entity-Ref-ID": "F-2026-042"},
})

响应 200:

JSON
{ "id": "4f9c1e0a-5b8d-4c7e-9a31-2d6f8b0c7e15", "suppressed": [] }

suppressed 列出因位于该域名的禁止发送列表中(硬退信、投诉)而被排除的收件人:他们不会收到任何邮件。

字段

字段规则
from名称 <地址> 或 地址,必须属于密钥的某个域名(规则)
to、cc、bcc一个地址或一个数组;总共最多 50 个收件人,至少一个 to
reply_to一个地址或一个数组,最多 5 个
subject单行,最多 998 个字符
html、text至少提供其中之一
headers最多 20 个请求头;结构性邮件头(From、Subject、Message-ID、List-*、DKIM-*…)会被拒绝
tags[{name, value}] 或 {名称: 值},最多 10 个
attachments见下文
scheduled_at参见定时发送
template{alias 或 id, variables}:编辑器中已发布的模板(应用密钥)

未知字段会被拒绝(422),以免拼写错误被悄悄忽略。

附件

content 采用 base64 编码,最多 20 个文件、10 MB(解码后)。嵌入 HTML 中的图片需带有 content_id,并通过 cid: 引用。不支持通过 URL(path)下载附件:请直接发送内容。

Node / Bun

import { readFile } from "node:fs/promises"

await voaaro.emails.send({
  from: "Acme <invoices@example.com>",
  to: "client@example.org",
  subject: "Your invoice",
  html: '<img src="cid:logo"><p>Invoice attached.</p>',
  attachments: [
    { filename: "invoice.pdf", content: await readFile("invoice.pdf") }, // encoded by the SDK
    { filename: "logo.png", content: logoBase64, contentType: "image/png", contentId: "logo" },
  ],
})

Python

with open("invoice.pdf", "rb") as f:
    pdf = f.read()

voaaro.Emails.send({
    "from": "Acme <invoices@example.com>",
    "to": "client@example.org",
    "subject": "Your invoice",
    "html": "<p>Invoice attached.</p>",
    "attachments": [{"filename": "invoice.pdf", "content": pdf}],  # bytes encoded by the SDK
})

PHP

use Voaaro\Attachment;

$voaaro->emails->send([
    'from' => 'Acme <invoices@example.com>',
    'to' => 'client@example.org',
    'subject' => 'Your invoice',
    'html' => '<p>Invoice attached.</p>',
    'attachments' => [Attachment::fromPath('/invoices/F-2026-042.pdf')],
]);

Go

pdf, _ := os.ReadFile("invoice.pdf")

sent, err := client.Emails.Send(&voaaro.SendEmailRequest{
	From:        "Acme <invoices@example.com>",
	To:          []string{"client@example.org"},
	Subject:     "Your invoice",
	Html:        "<p>Invoice attached.</p>",
	Attachments: []*voaaro.Attachment{{Filename: "invoice.pdf", Content: pdf}}, // raw bytes
})

cURL

curl https://mail.example.com/api/v1/emails \
  -H "Authorization: Bearer $VOAARO_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"from\": \"Acme <invoices@example.com>\",
    \"to\": \"client@example.org\",
    \"subject\": \"Your invoice\",
    \"html\": \"<p>Invoice attached.</p>\",
    \"attachments\": [{\"filename\": \"invoice.pdf\", \"content\": \"$(base64 -w0 invoice.pdf)\"}]
  }"

对于大于 10 MB 的文件,网页邮箱提供通过链接发送的方式;通过 API 时,请自行托管文件并在邮件中放入链接。

定时发送

scheduled_at(或 send_at):一个 RFC 3339 日期(2026-11-20T08:00:00Z、2026-11-20T09:00:00+01:00),或 in <数字><单位> 形式的延迟(in 30 min、in 2 hours、in 1 day),最多 30 天。过去的日期会立即发送。

Node / Bun

const { data } = await voaaro.emails.send({ from, to, subject: "Reminder", text: "…", scheduledAt: "in 1 hour" })
await voaaro.emails.update({ id: data.id, scheduledAt: "2026-11-20T08:00:00Z" })
await voaaro.emails.cancel(data.id)

Python

email = voaaro.Emails.send({**params, "scheduled_at": "in 1 hour"})
voaaro.Emails.update({"id": email["id"], "scheduled_at": "2026-11-20T08:00:00Z"})
voaaro.Emails.cancel(email["id"])

PHP

$email = $voaaro->emails->send([...$params, 'scheduledAt' => 'in 1 hour']);
$voaaro->emails->update($email->id, ['scheduledAt' => '2026-11-20T08:00:00Z']);
$voaaro->emails->cancel($email->id);

Go

sent, _ := client.Emails.Send(&voaaro.SendEmailRequest{From: from, To: to, Subject: "Reminder", Text: "…", ScheduledAt: "in 1 hour"})
client.Emails.Update(&voaaro.UpdateEmailRequest{Id: sent.Id, ScheduledAt: "2026-11-20T08:00:00Z"})
client.Emails.Cancel(sent.Id)

cURL

curl -X PATCH https://mail.example.com/api/v1/emails/$ID \
  -H "Authorization: Bearer $VOAARO_API_KEY" -H "Content-Type: application/json" \
  -d '{"scheduled_at": "2026-11-20T08:00:00Z"}'

curl -X POST https://mail.example.com/api/v1/emails/$ID/cancel \
  -H "Authorization: Bearer $VOAARO_API_KEY"

只有在邮件尚未发出时才能重新定时或取消(否则返回 409)。

幂等性

网络在不恰当的时刻中断时,不应导致同一个验证码被发送两次。请添加一个 Idempotency-Key 请求头(1 到 256 个可打印 ASCII 字符),且该值对于这封邮件是唯一的:

情况(同一 API 密钥,24 小时内)响应
相同的幂等键,相同的请求原样重放第一次的响应,并附带 Idempotent-Replayed: true 请求头;不会重复执行任何操作
相同的幂等键,不同的请求409 invalid_idempotent_request
两个相同的请求同时到达第一个请求胜出;另一个收到重放的响应或 409 concurrent_idempotent_requests
键为空或超过 256 个字符422 invalid_idempotency_key

请求体会逐字节比较:请重新发送完全相同的请求。只有成功的响应(2xx)会被保存:出错后,请修正问题并使用相同的键重试。24 小时后,该键会被释放。每个 API 密钥都有自己独立的幂等键。

cURL

curl https://mail.example.com/api/v1/emails \
  -H "Authorization: Bearer $VOAARO_API_KEY" \
  -H "Idempotency-Key: otp-482913" \
  -H "Content-Type: application/json" \
  -d '{"from": "Acme <security@example.com>", "to": "client@example.org", "subject": "Your code: 482913", "text": "482913"}'

Node / Bun

await voaaro.emails.send(params, { idempotencyKey: "otp-482913" })

Python

voaaro.Emails.send(params, {"idempotency_key": "otp-482913"})

PHP

$voaaro->emails->send($params, ['idempotencyKey' => 'otp-482913']);

Go

client.Emails.SendWithOptions(ctx, req, &voaaro.SendEmailOptions{IdempotencyKey: "otp-482913"})

所有创建操作

相同的规则适用于 /api/v1 上的所有 POST 请求:联系人、分组、营销邮件、表单、webhook、密钥、添加到禁止发送列表等。连接中断后的重试绝不会创建两个对象。

  • 参与比较的请求包括方法、路径、参数、内容类型和请求体(对于以 multipart/form-data 上传的文件,客户端随机生成的分隔符不计入比较)。
  • 保存的响应在服务器上是加密的:其中可能包含机密信息(新建的 API 密钥、webhook 密钥),重试时会原样返回。
  • PATCH 和 DELETE 不需要幂等键:重放它们会得到相同的状态。
cURL
curl https://mail.example.com/api/v1/webhooks \
  -H "Authorization: Bearer $VOAARO_API_KEY" \
  -H "Idempotency-Key: webhook-production-1" \
  -H "Content-Type: application/json" \
  -d '{"endpoint": "https://app.example.com/webhooks/voaaro", "events": ["email.bounced", "contact.unsubscribed"]}'

在允许重试的情况下,SDK 会为每个 POST 自动生成一个键(UUID),并在多次尝试之间保持不变(SDK)。

批量发送

POST /api/v1/emails/batch:一个包含 1 到 100 封邮件的数组,每封邮件的字段与单封发送相同(包括附件、定时发送和模板),整个请求最大 16 MB。

  • x-batch-validation: strict(默认):先验证所有内容,再一次性写入;任何一个错误都会导致整批被拒绝(消息以 message <序号> 开头)。
  • x-batch-validation: permissive:有效的邮件会被发出,其他邮件会列在 errors: [{index, message}] 中。

使用 Idempotency-Key: K 时,每封邮件分别获得键 K#0、K#1…

Node / Bun

const { data, error } = await voaaro.batch.send(
  [
    { from: "Acme <notifications@example.com>", to: "a@example.org", subject: "Hello A", text: "…" },
    { from: "Acme <notifications@example.com>", to: "b@example.org", subject: "Hello B", text: "…" },
  ],
  { idempotencyKey: "reminder-2026-11-12", batchValidation: "permissive" },
)
// data.data: [{ id, suppressed }], data.errors: [{ index, message }]

Python

r = voaaro.Batch.send(
    [
        {"from": "Acme <notifications@example.com>", "to": "a@example.org", "subject": "Hello A", "text": "…"},
        {"from": "Acme <notifications@example.com>", "to": "b@example.org", "subject": "Hello B", "text": "…"},
    ],
    {"idempotency_key": "reminder-2026-11-12", "batch_validation": "permissive"},
)

PHP

$lot = $voaaro->batch->send(
    [
        ['from' => 'Acme <notifications@example.com>', 'to' => 'a@example.org', 'subject' => 'Hello A', 'text' => '…'],
        ['from' => 'Acme <notifications@example.com>', 'to' => 'b@example.org', 'subject' => 'Hello B', 'text' => '…'],
    ],
    ['idempotencyKey' => 'reminder-2026-11-12', 'batchValidation' => 'permissive'],
);

Go

resp, err := client.Batch.SendWithOptions(ctx, []*voaaro.SendEmailRequest{
	{From: "Acme <notifications@example.com>", To: []string{"a@example.org"}, Subject: "Hello A", Text: "…"},
	{From: "Acme <notifications@example.com>", To: []string{"b@example.org"}, Subject: "Hello B", Text: "…"},
}, &voaaro.BatchSendEmailOptions{IdempotencyKey: "reminder-2026-11-12", BatchValidation: voaaro.BatchValidationPermissive})

cURL

curl https://mail.example.com/api/v1/emails/batch \
  -H "Authorization: Bearer $VOAARO_API_KEY" \
  -H "x-batch-validation: permissive" \
  -H "Content-Type: application/json" \
  -d '[
    {"from": "Acme <notifications@example.com>", "to": "a@example.org", "subject": "Hello A", "text": "…"},
    {"from": "Acme <notifications@example.com>", "to": "b@example.org", "subject": "Hello B", "text": "…"}
  ]'

跟踪发送

GET /api/v1/emails/{id} 返回邮件的状态(queued、sending、sent、failed、canceled)、最新事件 last_event、每个收件人及其状态和远程服务器的响应、事件列表、内容和附件。GET /api/v1/emails 按从新到旧的顺序列出已发送的邮件(分页)。

last_event含义
queued、scheduled已接受,等待中(已定时)
sent已交给邮件引擎
delivered已被收件人的服务器接受
delivery_delayed暂时被拒,已安排重试
bounced永久被拒
failed已放弃(直到最后都被暂时拒绝,或所有收件人都被禁止发送)
suppressed收件人位于禁止发送列表中
complained收件人将邮件举报为垃圾邮件
opened、clicked打开、点击(如果密钥启用了跟踪)
canceled已取消

打开和点击跟踪按密钥在控制台中设置(默认停用)。邮件在发送后保留 30 天。

某次发送的附件:先调用 GET /api/v1/emails/{id}/attachments,再调用 GET …/attachments/{attachment},后者返回一个签名的 download_url,有效期一小时。

分享链接:POST /api/v1/emails/{id}/share(expires_in 为 1 分钟到 48 小时)会为该邮件创建一个只读的公开页面,其中不包含密送信息。

统计信息

GET /api/v1/emails/metrics(别名 /api/v1/metrics):计数器 received(被 API 接受)、sent、delivered、delivery_delayed、bounced、failed、suppressed、complained、opened(所有打开次数,每次加载跟踪像素都计入)、unique_opened(至少被打开过一次的邮件)、clicked,以及各项比率(delivery_rate、基于唯一打开数的 open_rate、click_rate、bounce_rate、complaint_rate,以百分比表示)。

参数取值
start_date、end_dateYYYY-MM-DD(默认为最近 7 天,最长三年)
granularitydaily(默认)、weekly、monthly
dimensionsperiod、domain、api_key、tag
metrics要返回的计数器和比率(metrics=sent,delivered);默认返回全部
domain、api_key_id筛选条件

sending_access 密钥只能看到它自己的数据。所有日期均为 UTC。

Esc