邮件

关于一封捕获邮件的一切:列表、解析后的详情、原始字节、附件、它链接到哪里,以及它在真实收件箱里会有怎样的表现。

列出沙箱中的邮件

GET /api/v1/sandboxes/{sandbox_id}/emails?limit=50&cursor=…&query=…
Scope: emails:read

Response:
{
  "data": [
    {
      "id": "e9v2h6r4ldq1a7c3",
      "subject": "Reset your password",
      "from_name": "Acme",
      "from_email": "noreply@acme.dev",
      "excerpt": "Click the link below to choose a new password…",
      "has_attachments": false,
      "attachment_count": 0,
      "received_at": "2026-09-02T09:14:22.000000Z"
    }
  ],
  "meta": { "total": 128, "next_cursor": "e9v2h6r4ldq1a7c3" }
}
列出沙箱邮件时的查询参数
参数取值
limit整数,1–100,默认 50
cursor上一页的 meta.next_cursor,见分页
query字符串,≤ 255 个字符。对主题、发件人和正文做全文搜索,使用的索引与应用的搜索框相同

跨沙箱搜索

GET /api/v1/emails?query=invoice&sandbox[]={sandbox_id}&sandbox[]={sandbox_id}
Scope: emails:read

响应结构和参数与列表接口相同,范围是令牌能访问的所有沙箱。sandbox[] 可以把范围缩小到其中几个;令牌无权访问的 id 会被直接跳过,不参与搜索。

读取单封邮件

GET /api/v1/emails/{email_id}
Scope: emails:read

Response:
{
  "id": "e9v2h6r4ldq1a7c3",
  "subject": "Reset your password",
  "from_name": "Acme",
  "from_email": "noreply@acme.dev",
  "recipients": [{ "type": "to", "email": "user@example.com", "name": "" }],
  "text_body": "Click the link below…",
  "html_body": "<!doctype html>…",
  "headers": { "message-id": "<…>", "dkim-signature": "…", "…": "…" },
  "attachment_count": 1,
  "attachments": [
    {
      "id": "a4d8k1p2m7x9c3v6",
      "filename": "receipt.pdf",
      "mime_type": "application/pdf",
      "size": 48213,
      "inline": false,
      "download_url": "https://app.mailclutch.com/api/v1/emails/e9v2h6r4ldq1a7c3/attachments/a4d8k1p2m7x9c3v6"
    }
  ],
  "received_at": "2026-09-02T09:14:22.000000Z",
  "sandbox": { "id": "k3n8x2p9qa7c1m4z", "name": "Acme — staging" }
}

正文按邮件携带的原样返回,只经过 MIME 解析。附件的 download_url 为 null,表示文件有记录但没有存储:文件过大,或者属于处理流程拒收的类型。

原始邮件及其附件

GET /api/v1/emails/{email_id}/raw
Scope: emails:read
→ message/rfc822, byte for byte as captured

GET /api/v1/emails/{email_id}/attachments/{attachment_id}
Scope: emails:read
→ the file, with its own Content-Type and a Content-Disposition filename

原始邮件端点就是导出功能:存成 .eml,用邮件客户端打开,或者交给其他工具处理。两者返回时都带有 X-Content-Type-Options: nosniff。

超过 25 MB 的附件不会单独存储:邮件会保留,附件会列出但没有文件,它的字节仍在原始邮件中。

送达率分析

GET /api/v1/emails/{email_id}/analysis
Scope: analysis:run

Response:
{
  "email_id": "e9v2h6r4ldq1a7c3",
  "deliverability": {
    "score": 82,
    "by_category": { "authentication": 30, "content": 22, "…": … },
    "factors": [
      { "key": "dkim", "label": "DKIM signature", "status": "pass", "…": … },
      { "key": "list_unsubscribe", "label": "List-Unsubscribe header", "status": "warning", "…": … }
    ],
    "spam_assassin": { "score": 1.2, "threshold": 5, "rules": [ … ] }
  },
  "authentication": { "spf": { … }, "dkim": { … }, "dmarc": { … } },
  "bimi": { … }
}

一个百分制评分,以及拉低分数的因素:SPF、DKIM、DMARC、BIMI、List-Unsubscribe 和一轮垃圾邮件过滤检查。它描述的是捕获到的这封邮件和你发信所用的主机;沙箱不是你生产环境的发信路径,所以这个评分针对的是邮件本身,而不是你的信誉。

删除单封邮件,或清空沙箱

DELETE /api/v1/emails/{email_id}
Scope: emails:delete
→ { "deleted": true }

DELETE /api/v1/sandboxes/{sandbox_id}/emails
Scope: emails:purge
→ { "deleted": 128 }

在永久沙箱上开始一次运行之前先清空很方便,这样里面就只有本次运行产生的邮件。如果每次运行用一个临时沙箱,就没有什么需要清空的,这种做法详见 CI / 断言指南。