代理人用的电子邮件。专为需要通过程序化方式发送、接收和理解电子邮件的 AI 代理人而构建
面向 AI Agent 的邮件基础设施。通过编程方式收发邮件。 English | 日本語 | 中文
…env.EMAIL.send() binding,公开 beta)与 Resend 互为兜底,默认顺序 cloudflare,resend,通过 EMAIL_PROVIDERS 覆盖--attach 或 SDK 发送,Worker 自动解析 MIME 附件/api/send 响应与 /api/inbox 的 outbound 行携带 provider 字段(cloudflare/resend),知道是谁真正投递的fetch(),不引 SDKmails claim 免费获取 @mails.dev 邮箱npm install -g mails
# 或
bun install -g mails
# 或直接使用
npx mailsCLI 最多每 24 小时检查一次 npm;发现新版本时,会在 stderr 打印升级提醒。可用 MAILS_NO_UPDATE_CHECK=1 关闭(设置 NO_UPDATE_NOTIFIER=1 或 CI=1 时也会跳过检查)。
mails claim myagent # 免费认领 [email protected]
mails send --to [email protected] --subject "Hello" --body "World" # 每月 100 封免费
mails inbox # 查看收件箱
mails inbox --query "密码" # 搜索邮件
mails code --to [email protected] # 等待验证码无需 Resend key — 托管用户每月 100 封免费发件。无限发送请配置自己的 key:mails config set resend_api_key re_YOUR_KEY
…mails claim # 认领 [email protected](每人最多 10 个)mails send --to --subject --body
mails send --to --subject --html "
Hello
"
mails send --from "Name " --to --subject --body
mails send --to --subject --body --reply-to
mails send --to --subject "Report" --body "See attached" --attach report.pdfmails inbox # 最近邮件列表
mails inbox --full-id # 列表显示完整邮件 ID(默认只显示前 8 位)
mails inbox --mailbox [email protected] # 指定邮箱
mails inbox --query "password reset" # 全文搜索(按相关性排序)
mails inbox --query "invoice" --direction inbound --limit 10
mails inbox # 查看邮件详情 + 附件
mails inbox --save # 下载附件到当前目录
mails inbox --save ./downloads # 下载附件到指定目录高级查询能力(附件 / 发件人 / 时间 / 邮件头过滤,以及发件人统计)目前仅通过 mails.dev 托管 HTTP API 提供,尚未接入
mailsCLI 或 SDK。详见 docs/advanced-query-api.md。
mails code --to [email protected] # 等待验证码(默认 30 秒)
mails code --to [email protected] --timeout 60 # 自定义超时验证码输出到 stdout,方便管道使用:CODE=$(mails code --to [email protected])
mails config # 查看所有配置
mails config set # 设置配置项
mails config get # 获取配置项
mails config path # 显示配置文件路径mails sync # 从 Worker 同步邮件到本地存储
mails sync --since 2026-03-01 # 从指定日期同步
mails sync --from-scratch # 全量重新同步从 Worker(托管或自部署)拉取邮件到本地 SQLite。适用于离线访问或本地备份。
…worker/ 目录包含用于接收邮件的 Cloudflare Email Routing Worker。
cd worker
bun install
wrangler d1 create mails
# 编辑 wrangler.toml — 设置你的 D1 数据库 ID
wrangler d1 execute mails --file=schema.sql
wrangler deploy然后在 Cloudflare Email Routing 中配置转发到该 Worker。
# 单邮箱:
# [email protected]
# AUTH_TOKEN=YOUR_MAILBOX_TOKEN
# 多邮箱:
# AUTH_TOKENS_JSON={"[email protected]":"token1","[email protected]":"token2"}所有 /api/* 端点都需要 Authorization: Bearer 。这个 token 必须和 ?to=、被读取的邮件、或发送时的 from 邮箱一致。/health 始终公开。若未配置 mailbox token,访问 /api/* 会返回 503。
| 端点 | 说明 |
|---|---|
GET /api/inbox?to=&limit=20 |
邮件列表 |
GET /api/inbox?to=&query= |
搜索邮件 |
GET /api/code?to=&timeout=30 |
长轮询等待验证码 |
GET /api/email?id= |
邮件详情(含附件) |
POST /api/send |
通过 provider 链发送邮件(Cloudflare Email Service、Resend) |
GET /api/sync?to=&since= |
增量邮件同步(含附件) |
GET /health |
健康检查(始终公开) |
CLI 自动检测存储 Provider:
api_key → 远程(mails.dev 托管)worker_url → 远程(自部署 Worker)本地数据库,路径 ~/.mails/mails.db。零配置。
面向 AI Agent 的云端 PostgreSQL。支持全文搜索(按相关性排序)、附件内容搜索和高级过滤。
mails config set storage_provider db9
mails config set db9_token YOUR_TOKEN
mails config set db9_database_id YOUR_DB_ID使用 db9 后可获得:
以上高级能力通过 mails.dev 托管 HTTP API 暴露(见
docs/advanced-query-api.md);mails CLI/SDK
目前只透传 query、direction 和 limit。
直接查询 Worker HTTP API。配置了 api_key 或 worker_url 时自动启用。
| 键 | 默认值 | 说明 |
|---|---|---|
mailbox |
接收邮箱地址 | |
api_key |
mails.dev 托管服务 API key | |
worker_url |
自部署 Worker URL | |
worker_token |
自部署 Worker 的 mailbox token | |
resend_api_key |
Resend API 密钥 | |
default_from |
默认发件人地址 | |
storage_provider |
auto | sqlite、db9 或 remote |
db9_token |
db9.ai 云存储 token | |
db9_database_id |
db9.ai 数据库 ID | |
last_sync |
上次 mails sync 运行的时间戳(自动管理) |
bun test # 单元 + E2E 测试(无需外部依赖)
bun test:coverage # 附带覆盖率报告
bun test:live # 实时 E2E 测试(需要 .env 配置)
bun test:all # 全部测试(包括实时 E2E)198 个单元测试 + 27 个 E2E 测试 = 225 个测试,覆盖全部 Provider。
| SQLite | db9 | Remote (OSS) | Remote (托管) | |
|---|---|---|---|---|
| 存储 inbound 邮件 | ✅ | ✅ | N/A | N/A |
| 存储邮件 + 附件 | ✅ | ✅ | N/A | N/A |
| 发送 → 接收(真实链路) | ✅ | — | ✅ | ✅ |
| 收件箱列表 | ✅ | ✅ | ✅ | ✅ |
| has_attachments 标记 | ✅ | ✅ | ✅ | ✅ |
| 方向过滤 | ✅ | ✅ | ✅ | ✅ |
| 分页 | ✅ | ✅ | ✅ | ✅ |
| 邮件详情 | ✅ | ✅ | ✅ | ✅ |
| 附件元数据 | ✅ | ✅ | ✅ | ✅ |
| 搜索 | ✅ | ✅ | ✅ | ✅ |
| 附件内容搜索 | ✅ | ✅ | — | — |
| 验证码 | ✅ | ✅ | ✅ | ✅ |
| 附件下载 | ✅ | ✅ | — | ✅ |
| 保存到磁盘 (--save) | ✅ | — | — | ✅ |
| 邮箱隔离 | ✅ | ✅ | — | — |
| Outbound 记录 | ✅ | — | ✅ | N/A |
| 通过 Worker 发送 (/api/send) | — | — | ✅ | — |
| 同步到本地 | — | — | ✅ | — |
MIT
暂无开放 Issues,或尚未同步最近议题。