Documentation Index
Fetch the complete documentation index at: https://resend.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Use this pre-built prompt with your AI agent to build with the Resend Chat SDK adapter.
The @resend/chat-sdk-adapter package is a Vercel Chat SDK adapter that turns email into a two-way communication channel via Resend. Receive inbound emails through webhooks, reply through the Resend API, and let the adapter handle threading automatically. The adapter is open source and available on GitHub.
Prerequisites
To get started, you’ll need to:
- Create an API key
- Verify your domain
- Set up webhooks for
email.receivedevents - Enable receiving on your domain
1. Install
npm
npm install @resend/chat-sdk-adapter chat @chat-adapter/state-memory
2. Configure the adapter
Create a Resend adapter and pass it to the Chat SDK.
import { createResendAdapter } from '@resend/chat-sdk-adapter';
import { MemoryStateAdapter } from '@chat-adapter/state-memory';
import { Chat } from 'chat';
const resend = createResendAdapter({
fromAddress: 'bot@example.com',
fromName: 'My Bot',
});
const chat = new Chat({
userName: 'email-bot',
adapters: { resend },
state: new MemoryStateAdapter(),
});
Configuration options
| Parameter | Type | Required | Description |
|---|---|---|---|
fromAddress | string | Yes | Sender email address |
fromName | string | No | Display name for the From header |
apiKey | string | No | Resend API key. Falls back to RESEND_API_KEY env var |
webhookSecret | string | No | Webhook signing secret. Falls back to RESEND_WEBHOOK_SECRET env var |
3. Handle inbound emails
Register handlers for incoming emails. onNewMention fires when a new thread starts, and onSubscribedMessage fires for follow-up emails in threads you’ve subscribed to.
chat.onNewMention(async (thread, message) => {
console.log(`New email from ${message.author.userId}: ${message.text}`);
await thread.subscribe();
await thread.post(`Got your email: ${message.text}`);
});
chat.onSubscribedMessage(async (thread, message) => {
await thread.post(`Reply: ${message.text}`);
});
4. Forward webhooks
Point your Resend webhooks to your server’s /webhook endpoint. The adapter verifies the signature and parses the payload.
if (req.method === 'POST' && req.url === '/webhook') {
const result = await chat.webhooks.resend(request);
res.writeHead(result.status);
res.end();
}
The handler expects a Web Request object. If you’re using Node.js http, convert IncomingMessage to a Request first — see the basic example for a full working server. For webhook setup details, see Managing Webhooks and Verify Webhook Requests.
How threading works
The adapter resolves threads using standard Message-ID, In-Reply-To, and References email headers. Reply chains are automatically grouped into Chat SDK threads — no extra configuration needed.