feat(agents): add sendEmail() and rewrite email-agent example for Email Service#1279
Conversation
🦋 Changeset detectedLatest commit: fc5d3c3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
Replace the worker-only email routing demo with a full-stack app that shows outbound sends, inbound routing, and synced mailbox state. Update the docs to reflect Email Service terminology and setup.
Replace the concrete inboxbuddy.dev mailbox in the email-agent example with a neutral example address. This keeps the sample configuration and docs from pointing at a specific mailbox.
Upgrade @cloudflare/vite-plugin to ^1.32.3 in examples/email-agent/package.json and refresh package-lock.json to reflect updated and newly added runtime and dev dependencies for the example (including react, react-dom, @cloudflare/kumo, @phosphor-icons/react, @vitejs/plugin-react, tailwindcss, vite, and related TypeScript typedefs). This keeps the example's dependency tree and dev tooling in sync.
Introduce Agent.sendEmail with SendEmailOptions and EmailSendBinding types to send outbound mail via Cloudflare Email Service bindings. sendEmail injects X-Agent-Name/X-Agent-ID headers, supports In-Reply-To, and can HMAC-sign headers (secret) for secure reply routing. Remove legacy sendBinding usage from replyToEmail (replyToEmail now uses the inbound reply API), add email:send observability event, update docs and examples to use this.sendEmail(), and add comprehensive tests for sendEmail behavior and header signing.
fc5d3c3 to
beef4da
Compare
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <link rel="icon" href="/favicon.svg" /> |
There was a problem hiding this comment.
🟡 Example uses favicon.svg instead of required favicon.ico per AGENTS.md
The examples/AGENTS.md required structure mandates public/favicon.ico and the index.html template specifies <link rel="icon" href="/favicon.ico" />. This example has public/favicon.svg and <link rel="icon" href="/favicon.svg" />, which violates the mandatory convention. Most other examples (playground, mcp-client, assistant, etc.) use favicon.ico as required.
| <link rel="icon" href="/favicon.svg" /> | |
| <link rel="icon" href="/favicon.ico" /> |
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
Adds
sendEmail()to the Agent class for outbound email via Cloudflare Email Service, and rewritesexamples/email-agentinto a full-stack app that demonstrates both outbound sends and inbound routing.What changed
SDK:
sendEmail()method (packages/agents)New method on the Agent class for sending email through a
send_emailbinding:X-Agent-NameandX-Agent-IDheaders on every send.secretis provided, signs headers with HMAC-SHA256 so replies route back viacreateSecureReplyEmailResolver.inReplyTooption sets theIn-Reply-Toheader for threading deferred replies.email:sendobservability event on success.replyToEmail()is unchanged — still uses the runtimeemail.reply()path for live inbound replies.Exported types:
EmailSendBinding,SendEmailOptions.Example:
email-agentfull-stack rewriteReplaces the worker-only example with a Vite + React app using Kumo:
src/server.ts—EmailServiceAgentwith@callable()methods:sendTransactionalEmail(usesthis.sendEmail()),toggleAutoReply,clearActivity. Inbound viarouteAgentEmail()with combined secure/address resolver./api/simulate-emailendpoint for local testing.src/client.tsx— compose form, inbound simulator, inbox/outbox viewer, auto-reply toggle, connection indicator, dark mode.src/index.ts,run-tests.ts,test-mail.ts.Docs
docs/email.md— rewritten for Email Service terminology. New sections:sendEmail()usage, deferred replies pattern, API reference entry. Updated secure reply routing and error handling to referencesendEmail().docs/agent-class.md— updated email handling example to showsendEmail().docs/getting-started.md,docs/index.md,README.md— "Email Routing" → "Email Service".Validation
npm run checkpasses (all 73 projects typecheck, formatting clean, linting clean, exports valid).npm run test:workerspasses (944 tests, including 7 newsendEmailtests covering: missing binding, structured fields, In-Reply-To, HMAC signing, header merging, observability events).Reviewer notes
EMAIL_FROMbeing a verified sender in Cloudflare Email Service.EMAIL_SECRETis optional — without it the example still works but replies use address-based routing./api/simulate-emailendpoint is a dev-only helper for exercising inbound routing locally.