Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/send-email-binding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"agents": patch
---

Add `sendEmail()` method to the Agent class for sending outbound email via Cloudflare Email Service. Pass your `send_email` binding explicitly as `this.sendEmail({ binding: this.env.EMAIL, ... })`. Automatically injects agent routing headers and supports optional HMAC signing for secure reply routing.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ State changes sync to all connected clients automatically. Call methods like the
| **AI Chat** | Message persistence, resumable streaming, server/client tool execution |
| **MCP** | Act as MCP servers or connect as MCP clients |
| **Workflows** | Durable multi-step tasks with human-in-the-loop approval |
| **Email** | Receive and respond via Cloudflare Email Routing |
| **Email** | Send, receive, and reply via Cloudflare Email Service |
| **Code Mode** | LLMs generate executable TypeScript instead of individual tool calls |
| **SQL** | Direct SQLite queries via Durable Objects |
| **React Hooks** | `useAgent` and `useAgentChat` for frontend integration |
Expand Down
18 changes: 15 additions & 3 deletions docs/agent-class.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,27 @@ class MyAgent extends Agent {

### Email Handling

Agents can receive and reply to emails using Cloudflare's [Email Routing](https://developers.cloudflare.com/email-routing/email-workers/).
Agents can send and receive emails using Cloudflare's [Email Service](https://developers.cloudflare.com/email-service/).

Use `this.sendEmail()` with your `send_email` binding for outbound email:

```ts
class MyAgent extends Agent {
@callable()
async sendWelcome(to: string) {
return this.sendEmail({
binding: this.env.EMAIL,
to,
from: "support@yourdomain.com",
subject: "Welcome!",
text: "Thanks for signing up."
});
}

async onEmail(email: AgentEmail) {
console.log("Received email from:", email.from);
console.log("Subject:", email.headers.get("subject"));

// Reply to the email
await this.replyToEmail(email, {
fromName: "My Agent",
body: "Thanks for your email!"
Expand All @@ -375,7 +387,7 @@ export default {
};
```

For more details on email routing, resolvers, secure reply flows, and the full API, see the [Email Routing guide](./email.md).
For more details on `sendEmail()`, routing inbound mail, resolvers, and secure reply flows, see the [Email Service guide](./email.md).

### Context Management

Expand Down
Loading
Loading