Use this pre-built prompt with your AI agent to build with the Resend Chat SDK adapter.
@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, or forinbox.email.receivedevents when you use an inbox - Enable receiving on your domain
Guide
1
Install
2
Configure the adapter
Create a Resend adapter and pass it with adapter configuration options to the Chat SDK.
Set
RESEND_API_KEY and RESEND_WEBHOOK_SECRET as environment variables. You can also pass apiKey and webhookSecret directly in the config — explicit values take precedence over env vars.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.4
Forward webhooks
Point your Resend webhooks to your server’s The handler expects a Web
/webhook endpoint. The adapter verifies the signature and parses the payload.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 standardMessage-ID, In-Reply-To, and References email headers. Reply chains are automatically grouped into Chat SDK threads, with no extra configuration needed.
Configuration options
Use an inbox
SetinboxId or inboxEmailAddress to build the bot on a Resend Inbox. The inbox groups email into threads, and the bot replies inside the thread. Resend sets the recipients and the threading headers.
inboxId or inboxEmailAddress, not both. Setting both is a type error, and the adapter throws Set inboxId or inboxEmailAddress, not both. The inbox.email.received payload identifies the inbox by its ID. With inboxEmailAddress, the adapter gets the inbox ID with resend.inboxes.get() on the first inbox.email.received event and keeps it.
Subscribe your webhook to inbox.email.received. With an inbox set, the adapter:
- Handles
inbox.email.receivedevents for that inbox only, and ignores other inboxes andemail.receivedevents. - Maps each inbox thread to one Chat SDK thread.
- Gives each attachment
id,filename,sizeandcontentTypeonmessage.raw.attachments. ThecontentTypeis alwaysapplication/octet-stream. - Replies to the last received email of the thread. The reply goes to the email’s
Reply-Toaddresses, or to its sender when it has none. It is sent from the inbox address, sofromNamedoes not apply to it.
Reply-To to any address. Check message.raw.replyTo before the bot replies with anything sensitive. openDM() still sends with resend.emails.send() from fromAddress.
The inbox mode needs @resend/chat-sdk-adapter 0.5.0 or later and resend 6.34.1 or later.
Features
Card Emails
Send rich HTML emails with structured card elements.
Attachments
Handle inbound email attachments.
Proactive Outreach
Start new email threads without waiting for inbound.
Examples
Basic
Echo bot that replies to every email
Welcome Cards
Styled card email on first contact
Notifications
Proactive outbound via openDM and HTTP POST
Support Bot
Multi-turn conversations with subscribe/unsubscribe
Attachments
Detect attachments and reply with a summary