Skip to main content

Use this pre-built prompt with your AI agent to build with the Resend Chat SDK adapter.

Open in Cursor
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:

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 /webhook endpoint. The adapter verifies the signature and parses the payload.
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, with no extra configuration needed.
Email is immutable. The following operations throw NotImplementedError: editMessage, deleteMessage, addReaction, removeReaction, and startTyping.

Configuration options

Use an inbox

Set inboxId 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.
You can also select the inbox by its email address:
Set 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.received events for that inbox only, and ignores other inboxes and email.received events.
  • Maps each inbox thread to one Chat SDK thread.
  • Gives each attachment id, filename, size and contentType on message.raw.attachments. The contentType is always application/octet-stream.
  • Replies to the last received email of the thread. The reply goes to the email’s Reply-To addresses, or to its sender when it has none. It is sent from the inbox address, so fromName does not apply to it.
A sender can set 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