🔶 基于 AI 代理的自托管邮件客户端,运行在 Cloudflare Workers
英文标题:🔶 Self-hosted email client with an AI agent, running on Cloudflare Workers
Agentic Inbox 是一个完全自托管在 Cloudflare Workers 上的邮件客户端,通过 Cloudflare Email Routing 收发邮件,每个邮箱以独立 Durable Object 与 SQLite 存储隔离,附件存放于 R2。内置 AI 邮件代理可通过侧边栏工具读取、搜索和起草回复,发送前必须人工确认。该项目利用 Cloudflare Agents SDK 与 Workers AI 实现了完整的端到端邮件 AI 体验,并支持通过 MCP 对外提供工具能力,为开发者展示了以函数计算和持久化对象构建智能邮件系统的范式。
3.4 MB
58.4 KB
中文
一个完全运行在 Cloudflare Workers 上的自托管邮件客户端,并内置 AI 代理
Agentic Inbox 让你通过现代 Web 界面发送、接收和管理邮件 —— 所有一切都由你自己的 Cloudflare 账户驱动。收到的邮件通过 Cloudflare Email Routing 进入,每个邮箱被隔离在它自己的 Durable Object 中并使用 SQLite 数据库,附件存储在 R2 里。
内置的 AI 邮件代理 可以读取你的收件箱、搜索对话并起草回复 —— 使用 Cloudflare Agents SDK 和 Workers AI 构建。
阅读博客文章了解更多关于 Cloudflare Email Service 以及如何与 Agents SDK、MCP 和 Wrangler CLI 配合使用的信息:面向 Agent 的邮件服务。
重要提示:点击“Deploy to Cloudflare”按钮只是设置的一部分。你还必须按照 部署后的步骤 进行操作。如需包含截图的完整分步指南,请参考此评论:#4 (评论)
- 部署到 Cloudflare。部署流程会自动配置 R2、Durable Objects 和 Workers AI。系统会提示你输入 DOMAINS,即你希望接收邮件的域名(yourdomain.com),例如 email@yourdomain.com。
-
配置 Cloudflare Access —— 在 Worker 的 Settings > Domains & Routes 下启用 一键式 Cloudflare Access。模式对话框会显示你的
POLICY_AUD和TEAM_DOMAIN值。TEAM_DOMAIN可以是你的 Access 团队域名或完整的.../cdn-cgi/access/certsURL。你必须将这些设置为 Worker 的 secret。 -
设置 Email Routing —— 在 Cloudflare 仪表板中,进入你的域名 > Email Routing,并创建一条转发到此 Worker 的全捕获规则(catch-all rule)。
-
启用 Email Service —— Worker 需要
send_email绑定才能发送外发邮件。请参阅 Email Service 文档 -
创建邮箱 —— 访问你已部署的应用,为域名上的任意地址创建一个邮箱(例如
hello@example.com)
故障排除
- 如果你看到
Invalid or expired Access token,这通常意味着POLICY_AUD或TEAM_DOMAINsecret 不正确。 - 如果你看到
Cloudflare Access must be configured in production,该应用有意强制使用 Cloudflare Access,这样你的收件箱不会暴露在互联网上。
功能
- 完整的邮件客户端 —— 通过 Cloudflare Email Routing 收发邮件,带有富文本编辑器、回复/转发线程、文件夹组织、搜索和附件
- 每个邮箱独立隔离 —— 每个邮箱在其自己的 Durable Object 中运行,使用 SQLite 存储,附件存储在 R2
- 内置 AI 代理 —— 侧边面板带有 9 个邮件工具,可用于阅读、搜索、起草和发送
- 新邮件自动起草 —— 代理自动读取收到的邮件并生成回复草稿,发送前始终需要显式确认
- 可配置且持久化 —— 每个邮箱可自定义系统提示词,聊天历史持久化,流式 Markdown 响应,以及工具调用可见性
技术栈
- 前端: React 19, React Router v7, Tailwind CSS, Zustand, TipTap,
@cloudflare/kumo - 后端: Hono, Cloudflare Workers, Durable Objects (SQLite), R2, Email Routing
- AI 代理: Cloudflare Agents SDK (
AIChatAgent), AI SDK v6, Workers AI (@cf/moonshotai/kimi-k2.5),react-markdown+remark-gfm - 认证: Cloudflare Access JWT 认证(本地开发环境之外需要)
本地开发
- 在
wrangler.jsonc中设置你的域名 - 创建一个名为
agentic-inbox的 R2 bucket:wrangler r2 bucket create agentic-inbox
安全模型
任何通过共享 Cloudflare Access 策略的用户都可以访问此应用中的所有邮箱,这是设计使然。包括位于 /mcp 的 MCP 服务器 —— 通过 MCP 连接的外部 AI 工具(Claude Code、Cursor 等)可以通过传递 mailboxId 参数操作任意邮箱。没有每个邮箱的单独授权;Cloudflare Access 策略是唯一的信任边界。
┌──────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ 浏览器 │────>│ Hono Worker │────>│ MailboxDO │
│ React SPA │ │ (API + SSR) │ │ (SQLite + R2) │
│ Agent 面板 │ │ │ └─────────────────┘
└──────┬───────┘ │ /agents/* ──────┼────>┌─────────────────┐
│ │ │ │ EmailAgent DO │
│ WebSocket │ │ │ (AIChatAgent) │
└─────────────┤ │ │ 9 邮件工具 │
│ │────>│ Workers AI │
└──────────────────┘ └─────────────────┘
许可证
Apache 2.0 —— 参见 LICENSE。
English / 原文
A self-hosted email client with an AI agent, running entirely on Cloudflare Workers
Agentic Inbox lets you send, receive, and manage emails through a modern web interface -- all powered by your own Cloudflare account. Incoming emails arrive via Cloudflare Email Routing, each mailbox is isolated in its own Durable Object with a SQLite database, and attachments are stored in R2.
An AI-powered Email Agent can read your inbox, search conversations, and draft replies -- built with the Cloudflare Agents SDK and Workers AI.
Read the blog post to learn more about Cloudflare Email Service and how to use it with the Agents SDK, MCP, and from the Wrangler CLI: Email for Agents.
Important : Clicking the 'Deploy to Cloudflare' button is only one part of the setup. You must follow the After deploying steps as well. For a full step-by-step guide with screenshots, refer to this comment: #4 (comment)
- Deploy to Cloudflare. The deploy flow will automatically provision R2, Durable Objects, and Workers AI. You'll be prompted for DOMAINS , which is the domain (yourdomain.com) you want to receive emails for (email@yourdomain.com).
-
Configure Cloudflare Access -- Enable one-click Cloudflare Access on your Worker under Settings > Domains & Routes. The modal will show your
POLICY_AUDandTEAM_DOMAINvalues.TEAM_DOMAINcan be either your Access team URL or the full.../cdn-cgi/access/certsURL. You must set these as secrets for your Worker. -
Set up Email Routing -- In the Cloudflare dashboard, go to your domain > Email Routing and create a catch-all rule that forwards to this Worker
-
Enable Email Service -- The worker needs the
send_emailbinding to send outbound emails. See Email Service docs -
Create a mailbox -- Visit your deployed app and create a mailbox for any address on your domain (e.g.
hello@example.com) -
If you see
Invalid or expired Access token, that usually meansPOLICY_AUDorTEAM_DOMAINsecrets are incorrect. -
If you see
Cloudflare Access must be configured in production, this application is intentionally enforcing Cloudflare Access so your inbox is not exposed to anyone on the internet.
-
Full email client — Send and receive emails via Cloudflare Email Routing with a rich text composer, reply/forward threading, folder organization, search, and attachments
-
Per-mailbox isolation — Each mailbox runs in its own Durable Object with SQLite storage and R2 for attachments
-
Built-in AI agent — Side panel with 9 email tools for reading, searching, drafting, and sending
-
Auto-draft on new email — Agent automatically reads inbound emails and generates draft replies, always requiring explicit confirmation before sending
-
Configurable and persistent — Custom system prompts per mailbox, persistent chat history, streaming markdown responses, and tool call visibility
-
Frontend: React 19, React Router v7, Tailwind CSS, Zustand, TipTap,
@cloudflare/kumo -
Backend: Hono, Cloudflare Workers, Durable Objects (SQLite), R2, Email Routing
-
AI Agent: Cloudflare Agents SDK (
AIChatAgent), AI SDK v6, Workers AI (@cf/moonshotai/kimi-k2.5),react-markdown+remark-gfm -
Auth: Cloudflare Access JWT validation (required outside local development)
- Set your domain in
wrangler.jsonc - Create an R2 bucket named
agentic-inbox:wrangler r2 bucket create agentic-inbox
Any user who passes the shared Cloudflare Access policy can access all mailboxes in this app by design. This includes the MCP server at /mcp -- external AI tools (Claude Code, Cursor, etc.) connected via MCP can operate on any mailbox by passing a mailboxId parameter. There is no per-mailbox authorization; the Cloudflare Access policy is the single trust boundary.
┌──────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Browser │────>│ Hono Worker │────>│ MailboxDO │
│ React SPA │ │ (API + SSR) │ │ (SQLite + R2) │
│ Agent Panel │ │ │ └─────────────────┘
└──────┬───────┘ │ /agents/* ──────┼────>┌─────────────────┐
│ │ │ │ EmailAgent DO │
│ WebSocket │ │ │ (AIChatAgent) │
└─────────────┤ │ │ 9 email tools │
│ │────>│ Workers AI │
└──────────────────┘ └─────────────────┘
Apache 2.0 -- see LICENSE.
