Resend
Quick Send — Node.js
import { Resend } from 'resend';
const resend = new Resend(process.env.RESEND_API_KEY);
const { data, error } = await resend.emails.send(
{
from: 'Acme <onboarding@resend.dev>',
to: ['delivered@resend.dev'],
subject: 'Hello World',
html: '<p>Email body here</p>',
},
{ idempotencyKey: `welcome-email/${userId}` }
);
if (error) {
console.error('Failed:', error.message);
return;
}
console.log('Sent:', data.id);
Key gotcha: The Resend Node.js SDK does NOT throw exceptions — it returns { data, error }. Always check error explicitly instead of using try/catch for API errors.
Quick Send — Python
import resend
import os
resend.api_key = os.environ["RESEND_API_KEY"]
email = resend.Emails.send({
"from": "Acme <onboarding@resend.dev>",
"to": ["delivered@resend.dev"],
"subject": "Hello World",
"html": "<p>Email body here</p>",
}, idempotency_key=f"welcome-email/{user_id}")
Single vs Batch Decision
| Choose |
When |
Single (POST /emails) |
1 email, needs attachments, needs scheduling |
Batch (POST /emails/batch) |
2-100 distinct emails, no attachments, no scheduling |
Batch is atomic — if one email fails validation, the entire batch fails. Always validate before sending. Batch does NOT support attachments or scheduled_at.
Idempotency Keys (Critical for Retries)
Prevent duplicate emails when retrying failed requests:
| Key Facts |
|
| Format (single) |
<event-type>/<entity-id> (e.g., welcome-email/user-123) |
| Format (batch) |
batch-<event-type>/<batch-id> (e.g., batch-orders/batch-456) |
| Expiration |
24 hours |
| Max length |
256 characters |
| Same key + same payload |
Returns original response without resending |
| Same key + different payload |
Returns 409 error |
Quick Receive (Node.js)
import { Resend } from 'resend';
const resend = new Resend(process.env.RESEND_API_KEY);
export async function POST(req: Request) {
const payload = await req.text(); // Must use raw text, not req.json()
const event = resend.webhooks.verify({
payload,
headers: {
'svix-id': req.headers.get('svix-id'),
'svix-timestamp': req.headers.get('svix-timestamp'),
'svix-signature': req.headers.get('svix-signature'),
},
secret: process.env.RESEND_WEBHOOK_SECRET,
});
if (event.type === 'email.received') {
// Webhook has metadata only — call API for body
const { data: email } = await resend.emails.receiving.get(
event.data.email_id
);
console.log(email.text);
}
return new Response('OK', { status: 200 });
}
Key gotcha: Webhook payloads do NOT contain the email body. You must call resend.emails.receiving.get() separately.
What Do You Need?
| Task |
Reference |
| Send a single email |
sending/overview.md — parameters, deliverability, testing |
| Send batch emails |
sending/overview.md → sending/batch-email-examples.md |
| Full SDK examples (Node.js, Python, Go, cURL) |
sending/single-email-examples.md |
| Idempotency, retries, error handling |
sending/best-practices.md |
| Get, list, reschedule, cancel emails |
sending/email-management.md |
| Receive inbound emails |
receiving.md — domain setup, webhooks, attachments |
| Manage templates (CRUD, variables) |
templates.md — lifecycle, aliases, pagination |
| Set up webhooks (events, verification) |
webhooks.md — verification, CRUD, retry schedule, IP allowlist |
| Manage domains (create, verify, claim, DNS) |
domains.md — regions, TLS, tracking, claiming, capabilities |
| Manage contacts (CRUD, properties) |
contacts.md — segments, topics, custom properties, bulk CSV import |
| Send broadcasts (marketing campaigns) |
broadcasts.md — lifecycle, scheduling, template variables |
| Manage API keys |
api-keys.md — permission scoping, domain restrictions |
| View API request logs |
logs.md — list and retrieve API call history, debugging |
| Define contact properties |
contact-properties.md — custom fields for contacts |
| Manage segments (contact groups) |
segments.md — broadcast targeting, contact grouping |
| Manage topics (subscriptions) |
topics.md — opt-in/out preferences, broadcast filtering |
| Create automations (event-driven workflows) |
automations.md — steps, connections, runs, conditions |
| Define and send events (automation triggers) |
events.md — schemas, payloads, contact association |
| Install SDK (8+ languages) |
installation.md |
| Set up an AI agent inbox |
Install the agent-email-inbox skill — covers security levels for untrusted input |
SDK Version Requirements
Always install the latest SDK version. These are the minimum versions for full functionality (sending, receiving, webhook verification):
| Language |
Package |
Min Version |
Install |
| Node.js |
resend |
>= 6.14.0 |
npm install resend |
| Python |
resend |
>= 2.21.0 |
pip install resend |
| Go |
resend-go/v3 |
>= 3.1.0 |
go get github.com/resend/resend-go/v3 |
| Ruby |
resend |
>= 1.0.0 |
gem install resend |
| PHP |
resend/resend-php |
>= 1.1.0 |
composer require resend/resend-php |
| Rust |
resend-rs |
>= 0.20.0 |
cargo add resend-rs |
| Java |
resend-java |
>= 4.11.0 |
See installation.md |
| .NET |
Resend |
>= 0.2.1 |
dotnet add package Resend |
If the project already has a Resend SDK installed, check the version and upgrade if it's below the minimum. Older SDKs may be missing webhooks.verify(), emails.receiving.get(), or domains.claims.*.
See installation.md for full installation commands, language detection, and cURL fallback.
Common Setup
API Key
Store in environment variable — never hardcode:
export RESEND_API_KEY=re_xxxxxxxxx
Get your key at resend.com/api-keys.
Detect Project Language
Check for these files: package.json (Node.js), requirements.txt/pyproject.toml (Python), go.mod (Go), Gemfile (Ruby), composer.json (PHP), Cargo.toml (Rust), pom.xml/build.gradle (Java), *.csproj (.NET).
Common Mistakes
| # |
Mistake |
Fix |
| 1 |
Retrying without idempotency key |
Always include idempotency key — prevents duplicate sends on retry. Format: <event-type>/<entity-id> |
| 2 |
Not verifying webhook signatures |
Always verify with resend.webhooks.verify() — unverified events can't be trusted |
| 3 |
Template variable name mismatch |
Variable names are case-sensitive — must match the template definition exactly. Use triple mustache {{{VAR}}} syntax |
| 4 |
Expecting email body in webhook payload |
Webhooks contain metadata only — call resend.emails.receiving.get() for body content |
| 5 |
Using try/catch for Node.js SDK errors |
SDK returns { data, error } — check error explicitly, don't wrap in try/catch |
| 6 |
Using batch for emails with attachments |
Batch doesn't support attachments — use single sends instead |
| 7 |
Testing with fake emails (test@gmail.com) |
Use delivered@resend.dev — fake addresses bounce and hurt reputation |
| 8 |
Sending with draft template |
Templates must be published before sending — call .publish() first |
| 9 |
html + template in same send call |
Mutually exclusive — remove html/text/react when using template |
| 10 |
MX record not lowest priority for inbound |
Ensure Resend's MX has the lowest number (highest priority) or emails won't route |
| 11 |
403 when sending from resend.dev |
The default onboarding@resend.dev is a sandbox — it can only deliver to your Resend account email. Verify your own domain first |
| 12 |
403 domain mismatch |
The from address domain must exactly match a verified domain. Verified send.acme.com but sending from user@acme.com will fail |
| 13 |
Calling Resend API from the browser (CORS) |
The API does not support CORS — this is intentional to protect your API key. Always call from server-side (API routes, serverless functions) |
| 14 |
401 restricted_api_key |
A sending-only API key was used on a non-sending endpoint (domains, contacts, etc.). Create a full-access key instead |
Cross-Cutting Concerns
Send + Receive Together
Auto-replies, email forwarding, or any receive-then-send workflow requires both capabilities:
- Set up inbound domain first (see receiving.md)
- Set up sending (see sending/overview.md)
- Note: batch sending does NOT support attachments or scheduling — use single sends when forwarding with attachments
AI Agent Inbox
If your system processes untrusted email content and takes actions (refunds, database changes, forwarding), install the agent-email-inbox skill. This applies whether or not AI is involved — any system interpreting freeform email content from external senders needs security measures.
Marketing Emails
The sending capabilities in this skill are for transactional email (receipts, confirmations, notifications). For marketing campaigns to large subscriber lists with unsubscribe links and engagement tracking, use Resend Broadcasts — see broadcasts.md for the API.
Domain Warm-up
New domains must gradually increase sending volume. Day 1 limit: ~150 emails (new domain) or ~1,000 (existing domain). See the warm-up schedule in sending/overview.md.
Testing
Never test with fake addresses at real email providers (test@gmail.com, fake@outlook.com) — they bounce and destroy sender reputation.
| Address |
Result |
delivered@resend.dev |
Simulates successful delivery |
bounced@resend.dev |
Simulates hard bounce |
complained@resend.dev |
Simulates spam complaint |
Suppression List
Resend automatically suppresses hard-bounced and spam-complained addresses. Sending to suppressed addresses fires the email.suppressed webhook event instead of attempting delivery. Manage in Dashboard → Suppressions.
Webhook Event Types
| Event |
Trigger |
email.sent |
API request successful |
email.delivered |
Reached recipient's mail server |
email.bounced |
Permanently rejected (hard bounce) |
email.complained |
Recipient marked as spam |
email.opened / email.clicked |
Recipient engagement |
email.delivery_delayed |
Soft bounce, Resend retries |
email.received |
Inbound email arrived |
domain.* / contact.* |
Domain/contact changes |
See webhooks.md for full details, signature verification, and retry schedule.
Error Handling Quick Reference
| Code |
Action |
| 400, 422 |
Fix request parameters, don't retry |
| 401 |
Check API key — restricted_api_key means sending-only key used on non-sending endpoint |
| 403 |
Verify domain ownership — common causes: resend.dev sandbox, from domain mismatch, unverified domain |
| 409 |
Idempotency conflict — use new key or fix payload |
| 429 |
Rate limited — retry with exponential backoff (default rate limit: 2 req/s) |
| 500 |
Server error — retry with exponential backoff |
Resources
1---2name: resend3description: Use when working with the Resend email API — sending transactional emails (single or batch), receiving inbound emails via webhooks, managing email templates, tracking delivery events, managing domains, contacts, broadcasts, webhooks, API keys, automations, events, viewing API request logs, or setting up the Resend SDK. Always use this skill when the user mentions Resend, even for simple tasks like "send an email with Resend" — the skill contains critical gotchas (idempotency keys, webhook verification, template variable syntax) that prevent common production issues.4license: MIT5---6
7# Resend
8
9## Quick Send — Node.js
10
11```typescript
12import { Resend } from 'resend';
13
14const resend = new Resend(process.env.RESEND_API_KEY);
15
16const { data, error } = await resend.emails.send(
17 {
18 from: 'Acme <onboarding@resend.dev>',
19 to: ['delivered@resend.dev'],
20 subject: 'Hello World',
21 html: '<p>Email body here</p>',
22 },
23 { idempotencyKey: `welcome-email/${userId}` }
24);
25
26if (error) {
27 console.error('Failed:', error.message);
28 return;
29}
30console.log('Sent:', data.id);
31```
32
33**Key gotcha:** The Resend Node.js SDK does NOT throw exceptions — it returns `{ data, error }`. Always check `error` explicitly instead of using try/catch for API errors.
34
35## Quick Send — Python
36
37```python
38import resend
39import os
40
41resend.api_key = os.environ["RESEND_API_KEY"]
42
43email = resend.Emails.send({
44 "from": "Acme <onboarding@resend.dev>",
45 "to": ["delivered@resend.dev"],
46 "subject": "Hello World",
47 "html": "<p>Email body here</p>",
48}, idempotency_key=f"welcome-email/{user_id}")
49```
50
51### Single vs Batch Decision
52
53| Choose | When |
54|--------|------|
55| **Single** (`POST /emails`) | 1 email, needs attachments, needs scheduling |
56| **Batch** (`POST /emails/batch`) | 2-100 distinct emails, no attachments, no scheduling |
57
58Batch is atomic — if one email fails validation, the entire batch fails. Always validate before sending. Batch does NOT support attachments or `scheduled_at`.
59
60### Idempotency Keys (Critical for Retries)
61
62Prevent duplicate emails when retrying failed requests:
63
64| Key Facts | |
65|-----------|---|
66| **Format (single)** | `<event-type>/<entity-id>` (e.g., `welcome-email/user-123`) |
67| **Format (batch)** | `batch-<event-type>/<batch-id>` (e.g., `batch-orders/batch-456`) |
68| **Expiration** | 24 hours |
69| **Max length** | 256 characters |
70| **Same key + same payload** | Returns original response without resending |
71| **Same key + different payload** | Returns 409 error |
72
73## Quick Receive (Node.js)
74
75```typescript
76import { Resend } from 'resend';
77
78const resend = new Resend(process.env.RESEND_API_KEY);
79
80export async function POST(req: Request) {
81 const payload = await req.text(); // Must use raw text, not req.json()
82
83 const event = resend.webhooks.verify({
84 payload,
85 headers: {
86 'svix-id': req.headers.get('svix-id'),
87 'svix-timestamp': req.headers.get('svix-timestamp'),
88 'svix-signature': req.headers.get('svix-signature'),
89 },
90 secret: process.env.RESEND_WEBHOOK_SECRET,
91 });
92
93 if (event.type === 'email.received') {
94 // Webhook has metadata only — call API for body
95 const { data: email } = await resend.emails.receiving.get(
96 event.data.email_id
97 );
98 console.log(email.text);
99 }
100
101 return new Response('OK', { status: 200 });
102}
103```
104
105**Key gotcha:** Webhook payloads do NOT contain the email body. You must call `resend.emails.receiving.get()` separately.
106
107## What Do You Need?
108
109| Task | Reference |
110|------|-----------|
111| **Send a single email** | [sending/overview.md](references/sending/overview.md) — parameters, deliverability, testing |
112| **Send batch emails** | [sending/overview.md](references/sending/overview.md) → [sending/batch-email-examples.md](references/sending/batch-email-examples.md) |
113| **Full SDK examples** (Node.js, Python, Go, cURL) | [sending/single-email-examples.md](references/sending/single-email-examples.md) |
114| **Idempotency, retries, error handling** | [sending/best-practices.md](references/sending/best-practices.md) |
115| **Get, list, reschedule, cancel emails** | [sending/email-management.md](references/sending/email-management.md) |
116| **Receive inbound emails** | [receiving.md](references/receiving.md) — domain setup, webhooks, attachments |
117| **Manage templates** (CRUD, variables) | [templates.md](references/templates.md) — lifecycle, aliases, pagination |
118| **Set up webhooks** (events, verification) | [webhooks.md](references/webhooks.md) — verification, CRUD, retry schedule, IP allowlist |
119| **Manage domains** (create, verify, claim, DNS) | [domains.md](references/domains.md) — regions, TLS, tracking, claiming, capabilities |
120| **Manage contacts** (CRUD, properties) | [contacts.md](references/contacts.md) — segments, topics, custom properties, bulk CSV import |
121| **Send broadcasts** (marketing campaigns) | [broadcasts.md](references/broadcasts.md) — lifecycle, scheduling, template variables |
122| **Manage API keys** | [api-keys.md](references/api-keys.md) — permission scoping, domain restrictions |
123| **View API request logs** | [logs.md](references/logs.md) — list and retrieve API call history, debugging |
124| **Define contact properties** | [contact-properties.md](references/contact-properties.md) — custom fields for contacts |
125| **Manage segments** (contact groups) | [segments.md](references/segments.md) — broadcast targeting, contact grouping |
126| **Manage topics** (subscriptions) | [topics.md](references/topics.md) — opt-in/out preferences, broadcast filtering |
127| **Create automations** (event-driven workflows) | [automations.md](references/automations.md) — steps, connections, runs, conditions |
128| **Define and send events** (automation triggers) | [events.md](references/events.md) — schemas, payloads, contact association |
129| **Install SDK** (8+ languages) | [installation.md](references/installation.md) |
130| **Set up an AI agent inbox** | Install the `agent-email-inbox` skill — covers security levels for untrusted input |
131
132## SDK Version Requirements
133
134Always install the latest SDK version. These are the minimum versions for full functionality (sending, receiving, webhook verification):
135
136| Language | Package | Min Version | Install |
137|----------|---------|-------------|---------|
138| Node.js | `resend` | >= 6.14.0 | `npm install resend` |
139| Python | `resend` | >= 2.21.0 | `pip install resend` |
140| Go | `resend-go/v3` | >= 3.1.0 | `go get github.com/resend/resend-go/v3` |
141| Ruby | `resend` | >= 1.0.0 | `gem install resend` |
142| PHP | `resend/resend-php` | >= 1.1.0 | `composer require resend/resend-php` |
143| Rust | `resend-rs` | >= 0.20.0 | `cargo add resend-rs` |
144| Java | `resend-java` | >= 4.11.0 | See [installation.md](references/installation.md) |
145| .NET | `Resend` | >= 0.2.1 | `dotnet add package Resend` |
146
147> **If the project already has a Resend SDK installed**, check the version and upgrade if it's below the minimum. Older SDKs may be missing `webhooks.verify()`, `emails.receiving.get()`, or `domains.claims.*`.
148
149See [installation.md](references/installation.md) for full installation commands, language detection, and cURL fallback.
150
151## Common Setup
152
153### API Key
154
155Store in environment variable — never hardcode:
156```bash
157export RESEND_API_KEY=re_xxxxxxxxx
158```
159
160Get your key at [resend.com/api-keys](https://resend.com/api-keys).
161
162### Detect Project Language
163
164Check for these files: `package.json` (Node.js), `requirements.txt`/`pyproject.toml` (Python), `go.mod` (Go), `Gemfile` (Ruby), `composer.json` (PHP), `Cargo.toml` (Rust), `pom.xml`/`build.gradle` (Java), `*.csproj` (.NET).
165
166## Common Mistakes
167
168| # | Mistake | Fix |
169|---|---------|-----|
170| 1 | **Retrying without idempotency key** | Always include idempotency key — prevents duplicate sends on retry. Format: `<event-type>/<entity-id>` |
171| 2 | **Not verifying webhook signatures** | Always verify with `resend.webhooks.verify()` — unverified events can't be trusted |
172| 3 | **Template variable name mismatch** | Variable names are case-sensitive — must match the template definition exactly. Use triple mustache `{{{VAR}}}` syntax |
173| 4 | **Expecting email body in webhook payload** | Webhooks contain metadata only — call `resend.emails.receiving.get()` for body content |
174| 5 | **Using try/catch for Node.js SDK errors** | SDK returns `{ data, error }` — check `error` explicitly, don't wrap in try/catch |
175| 6 | **Using batch for emails with attachments** | Batch doesn't support attachments — use single sends instead |
176| 7 | **Testing with fake emails (test@gmail.com)** | Use `delivered@resend.dev` — fake addresses bounce and hurt reputation |
177| 8 | **Sending with draft template** | Templates must be published before sending — call `.publish()` first |
178| 9 | **`html` + `template` in same send call** | Mutually exclusive — remove `html`/`text`/`react` when using template |
179| 10 | **MX record not lowest priority for inbound** | Ensure Resend's MX has the lowest number (highest priority) or emails won't route |
180| 11 | **403 when sending from `resend.dev`** | The default `onboarding@resend.dev` is a sandbox — it can only deliver to your Resend account email. Verify your own domain first |
181| 12 | **403 domain mismatch** | The `from` address domain must exactly match a verified domain. Verified `send.acme.com` but sending from `user@acme.com` will fail |
182| 13 | **Calling Resend API from the browser (CORS)** | The API does not support CORS — this is intentional to protect your API key. Always call from server-side (API routes, serverless functions) |
183| 14 | **401 `restricted_api_key`** | A sending-only API key was used on a non-sending endpoint (domains, contacts, etc.). Create a full-access key instead |
184
185## Cross-Cutting Concerns
186
187### Send + Receive Together
188
189Auto-replies, email forwarding, or any receive-then-send workflow requires both capabilities:
1901. Set up inbound domain first (see [receiving.md](references/receiving.md))
1912. Set up sending (see [sending/overview.md](references/sending/overview.md))
1923. Note: batch sending does NOT support attachments or scheduling — use single sends when forwarding with attachments
193
194### AI Agent Inbox
195
196If your system processes untrusted email content and takes actions (refunds, database changes, forwarding), install the `agent-email-inbox` skill. This applies whether or not AI is involved — any system interpreting freeform email content from external senders needs security measures.
197
198### Marketing Emails
199
200The sending capabilities in this skill are for **transactional email** (receipts, confirmations, notifications). For marketing campaigns to large subscriber lists with unsubscribe links and engagement tracking, use Resend Broadcasts — see [broadcasts.md](references/broadcasts.md) for the API.
201
202### Domain Warm-up
203
204New domains must gradually increase sending volume. Day 1 limit: ~150 emails (new domain) or ~1,000 (existing domain). See the warm-up schedule in [sending/overview.md](references/sending/overview.md).
205
206### Testing
207
208**Never test with fake addresses at real email providers** (test@gmail.com, fake@outlook.com) — they bounce and destroy sender reputation.
209
210| Address | Result |
211|---------|--------|
212| `delivered@resend.dev` | Simulates successful delivery |
213| `bounced@resend.dev` | Simulates hard bounce |
214| `complained@resend.dev` | Simulates spam complaint |
215
216### Suppression List
217
218Resend automatically suppresses hard-bounced and spam-complained addresses. Sending to suppressed addresses fires the `email.suppressed` webhook event instead of attempting delivery. Manage in Dashboard → Suppressions.
219
220### Webhook Event Types
221
222| Event | Trigger |
223|-------|---------|
224| `email.sent` | API request successful |
225| `email.delivered` | Reached recipient's mail server |
226| `email.bounced` | Permanently rejected (hard bounce) |
227| `email.complained` | Recipient marked as spam |
228| `email.opened` / `email.clicked` | Recipient engagement |
229| `email.delivery_delayed` | Soft bounce, Resend retries |
230| `email.received` | Inbound email arrived |
231| `domain.*` / `contact.*` | Domain/contact changes |
232
233See [webhooks.md](references/webhooks.md) for full details, signature verification, and retry schedule.
234
235## Error Handling Quick Reference
236
237| Code | Action |
238|------|--------|
239| 400, 422 | Fix request parameters, don't retry |
240| 401 | Check API key — `restricted_api_key` means sending-only key used on non-sending endpoint |
241| 403 | Verify domain ownership — common causes: `resend.dev` sandbox, `from` domain mismatch, unverified domain |
242| 409 | Idempotency conflict — use new key or fix payload |
243| 429 | Rate limited — retry with exponential backoff (default rate limit: 2 req/s) |
244| 500 | Server error — retry with exponential backoff |
245
246## Resources
247
248- [Resend Documentation](https://resend.com/docs)
249- [API Reference](https://resend.com/docs/api-reference)
250- [Dashboard](https://resend.com/emails)