/email-with-resend
Consent-aware Resend email with queues, suppression, idempotency and signed webhooks.
Then type /email-with-resend in Claude Code, or describe the task and let it pick the skill.
What you get back contract tests · 10 Oct 2026
- A retry never sends twice
- User text escaped in HTML
- Bad address: no retry
- I've written the welcome and expense-split emails, but nothing sends them yet. Tallyroom has no signup flow, no database, and no "add expense" action; the dashboard shows hard-coded sample rows. So I built the email code as two server-side functions, and they need to be called from those handlers once they exist.
- Each email carries a fixed ID (one per user for welcome, one per expense and recipient for splits), so Resend won't send the same one twice if a call is retried.
- Bounces and spam complaints aren't handled.
RESEND_WEBHOOK_SECRETis already in.env.local, but without a database there's nowhere to record addresses to stop emailing.
Input → output from the run
Tallyroom needs email. When someone adds an expense, the people it's split with should get a short email, and new users should get a welcome email. Use Resend (key and sender are in .env.local).
/**
* Welcome email. Call once after the user row is created.
* user: { id, email, name? }
*/
export async function sendWelcomeEmail(user) {
const result = await sendEmail({
to: user.email,
...welcomeEmail({ name: user.name }),
idempotencyKey: `welcome:${user.id}`,
});
if (!result.ok) console.error("[email] welcome failed", { userId: user.id, ...result });
return result;
}When to use it
Use when an app needs transactional, lifecycle or campaign email through Resend.
Skip it for cold email to people who never signed up; that is cold-outreach.
The thinking behind itEmail is where trust is won or lost. Send with consent, suppression and retries handled, and the right message lands exactly once.
Output contract from the skill's Output section
Report message classes and triggers, files/templates/jobs changed, sender and environment-variable names, consent/preferences/suppression behavior, webhook and idempotency design, verification evidence/message IDs, and remaining DNS/dashboard/production checks.
How it checks its own work from the instructions
- Returned API errors and thrown network errors are both tested
- Webhooks tested with signed, invalid, and replayed payloads
- Bounce and complaint suppression is tested
- Sends go only to test recipients until production confirmed
Requirements what it needs
- Works in
- Codex, Claude Code, Cursor
- Needs
- project files, terminal commands, network access
The instructions SKILL.md · 30 lines
Instructions & references
Back to overview ↑On this page 4 sections
Email with Resend
Implement email as a reliable, permission-aware subsystem. This is not a cold-outreach workflow.
Workflow
- Inspect framework/runtime, installed Resend SDK version, queues/jobs, database and user fields, auth/admin roles, existing templates, email events, consent/preferences, suppression data, webhooks, and verified-domain configuration.
- Classify each requested message as transactional, security, lifecycle, or marketing. Do not scaffold re-engagement or campaigns by default. Ask about sender identity, jurisdiction/consent, and preference policy only when not established by the product.
- Read the Resend guide for send/batch/webhook patterns, sender authentication and the dated Gmail/Yahoo/Outlook sender rules, Contacts/Segments/Topics, suppression handling, unsubscribe design, and copy guidance relevant to the selected class. Facts there carry a check date; re-check any older than 90 days, or when the installed SDK differs, before relying on it. For raw API shapes, use Resend's official agent skill if installed, otherwise its docs.
- Centralize provider calls. Detect the installed SDK API, handle both returned
errorvalues and thrown transport/runtime errors, use idempotency keys for event-triggered sends, and return a typed result to the caller. - Escape untrusted template values or use React/provider templates. Generate both HTML and useful text. Keep sender/reply-to configuration server-side and use a verified sending subdomain where appropriate. Treat SPF, DKIM, and an aligned DMARC record (
p=noneminimum) as required before any marketing or bulk volume, not as optional hardening. - Do not block or silently abandon the primary transaction. Use a durable outbox/queue, or a runtime-supported post-response primitive with observability when loss is acceptable. Unawaited promises are not reliable in serverless runtimes.
- For campaigns, use Broadcasts to a Segment, scoped to a Topic for per-category opt-out, or a durable campaign job, rather than a long request loop. Do not hand-build per-category unsubscribe when Topics fit. Enforce consent, preferences, suppression, per-recipient idempotency, rate limits, cancellation, and an audit record. Require role-based admin authorization and confirmation of segment/count before send.
- Verify Resend webhook signatures over the raw body, deduplicate events, and process bounces/complaints/delivery failures into a suppression model. Never trust an unsigned event.
- Provide one-click unsubscribe (
List-UnsubscribeplusList-Unsubscribe-Post: List-Unsubscribe=One-Click, RFC 8058) and a visible body link on marketing and subscribed mail, and stop sending within 48 hours. Do not expose raw email addresses in URLs when an opaque signed identifier can be used. Keep transactional/security opt-outs separate from marketing preferences.
Verification
Test provider success plus returned API error, thrown network error, duplicate event, queue retry, invalid recipient, escaped user content, text rendering, verified sender/reply-to, signed/invalid/replayed webhook, bounce/complaint suppression, one-click unsubscribe POST, Topic opt-out, SPF/DKIM/DMARC alignment in received headers, unsubscribe/preferences, unauthorized campaign access, segment preview, and rate-limit behavior. Run repository lint/type/test/build commands and send only to designated test recipients until production setup is confirmed.
Output
Report message classes and triggers, files/templates/jobs changed, sender and environment-variable names, consent/preferences/suppression behavior, webhook and idempotency design, verification evidence/message IDs, SPF/DKIM/DMARC status and expected daily volume against the dated sender rules, and remaining DNS/dashboard/production checks.
Resend implementation guide
Read only the sections needed for the selected transactional, lifecycle, or marketing email path. Vendor facts here were checked 2026-11-04 against resend 6.37.0 and the sources listed at the end. Re-check a fact before relying on it if that date is more than 90 days old or the installed SDK differs. For raw API shapes, prefer Resend's official agent skill (resend/resend-skills) if installed, otherwise the Resend docs.
Contents
- Send wrapper
- Templates and idempotency
- Durable delivery
- Sender authentication
- Mailbox sender rules
- Campaigns
- Webhooks and suppression
- Preferences and unsubscribe
- Copy guidance
- Verification
Send wrapper
Resend Node SDK calls (resend 6.37.0) return { data, error } for API failures and may also throw for runtime/transport failures. The SDK uses replyTo in Node options.
import { Resend } from 'resend';
const resend = new Resend(process.env.RESEND_API_KEY);
type SendResult =
| { ok: true; id: string }
| { ok: false; retryable: boolean; message: string };
export async function sendEmail(input: {
to: string | string[];
subject: string;
html: string;
text: string;
idempotencyKey: string;
}): Promise<SendResult> {
try {
const { data, error } = await resend.emails.send(
{
from: process.env.EMAIL_FROM!,
replyTo: process.env.EMAIL_REPLY_TO,
to: input.to,
subject: input.subject,
html: input.html,
text: input.text,
},
{ idempotencyKey: input.idempotencyKey },
);
if (error || !data?.id) {
return classifyResendError(error);
}
return { ok: true, id: data.id };
} catch (error) {
return classifyTransportError(error);
}
}
Adapt the second-argument/idempotency signature to the installed SDK version. Do not return success merely because the promise resolved.
Templates and idempotency
Prefer React Email or provider templates for structured escaping. If generating HTML manually, escape every untrusted name, URL, and content value. Include a useful text alternative and one primary action.
Derive idempotency keys from the logical event, for example welcome:{userId}:{signupEventId}. Resend idempotency keys are at most 256 characters and expire after 24 hours (checked 2026-11-04). Store send intent/status locally when delivery matters beyond that window.
Sender authentication
Use a verified sending domain/subdomain and a monitored reply-to. Resend domain verification requires SPF and DKIM. DMARC is not optional for bulk senders: Gmail, Yahoo, and Outlook.com require a published DMARC record (p=none minimum) with the From: domain aligned to SPF or DKIM once a domain sends 5,000+ messages a day to them. Gmail counts the whole primary domain, so a marketing subdomain and a transactional subdomain add up. Publish _dmarc with p=none and a working rua address first, confirm dmarc=pass in received headers from every sending service, then tighten to quarantine or reject (checked 2026-11-04: Resend DMARC guide). Treat dashboard/DNS status as manual until observed.
Mailbox sender rules (checked 2026-11-04)
These are mailbox-provider rules, not law. Before acting on them, re-fetch each source if this check date is more than 90 days old, or whenever a bounce code or postmaster dashboard disagrees with the table. Volumes are messages per day to that provider's consumer mailboxes. Gmail counts every message from the same primary domain, subdomains included, and a domain that crosses 5,000 once is classified as a bulk sender permanently.
| Provider | Applies to | Requirement | Source |
|---|---|---|---|
| Gmail | All senders to personal Gmail | SPF or DKIM. Valid forward and reverse DNS (PTR). TLS. RFC 5322 format. Spam rate in Postmaster Tools under 0.3%. | Gmail sender guidelines, checked 2026-11-04 |
| Gmail | 5,000+ per day | SPF and DKIM. DMARC published at p=none minimum, with the From: domain aligned to SPF or DKIM. PTR and TLS. Spam rate under 0.3%, aiming under 0.1%. Marketing and subscribed mail carries one-click unsubscribe per RFC 8058 (List-Unsubscribe: <https://...> plus List-Unsubscribe-Post: List-Unsubscribe=One-Click) and a visible unsubscribe link in the body. Transactional mail is exempt from one-click. Honor unsubscribes within 48 hours. Since November 2025 non-compliant mail gets temporary and permanent rejections. |
Gmail sender guidelines and sender guidelines FAQ, checked 2026-11-04 |
| Yahoo | All senders | SPF or DKIM. Spam rate under 0.3%. Valid forward and reverse DNS. RFC 5321 and 5322. | Yahoo sender requirements, checked 2026-11-04 |
| Yahoo | Bulk senders (no numeric threshold published) | SPF and DKIM. DMARC at p=none minimum that passes, relaxed alignment accepted. One-click List-Unsubscribe for marketing and subscribed mail: RFC 8058 POST highly recommended, mailto: accepted. Visible unsubscribe link in the body. Honor unsubscribes within 2 days. Spam rate under 0.3%. |
Yahoo sender requirements, checked 2026-11-04 |
| Outlook.com (outlook.com, hotmail.com, live.com) | Domains sending 5,000+ per day | SPF must pass. DKIM must pass. DMARC at p=none minimum, aligned with SPF or DKIM. Since 5 May 2025 non-compliant mail is rejected with 550 5.7.515 Access denied. A functional unsubscribe link is recommended. |
Microsoft, 2 Apr 2025, updated 30 Apr 2025, checked 2026-11-04 |
Google Workspace recipients are outside Gmail's sender guidelines; the table covers consumer mailboxes only.
Durable delivery
For user actions, write an outbox row in the same transaction as the triggering state change. A worker sends, records the Resend message ID, and retries classified transient failures with backoff. Use a dead-letter/alert path for permanent exhaustion.
Runtime-specific post-response primitives can be acceptable for low-value notifications, but an unawaited promise may be terminated in serverless environments. Do not hold a signup request open for network email delivery unless the email itself is the security transaction and the UX is designed for it.
Campaigns
Marketing/lifecycle email requires consent or another documented lawful basis and a product preference policy.
Resend's marketing model (checked 2026-11-04: Contacts) replaced Audiences. If the project still calls Audience endpoints, follow Resend's Audience-to-Contacts migration guide rather than mixing models.
- Contacts are global, one per email address, with custom properties and a global subscribed/unsubscribed status.
- Segments are sender-controlled targeting groups. Recipients never see them. A Contact needs a Segment to receive a Broadcast.
- Topics are recipient-controlled categories (for example "Product updates", "Newsletter"). A Broadcast scoped to a Topic skips Contacts who opted out of that Topic, and Resend shows the Topic on its hosted unsubscribe page so recipients can leave one category without leaving everything. The opt-in/opt-out default is fixed at creation.
When Broadcasts fit the job, use Segments for who and Topics for what. Do not rebuild per-category opt-out by hand. Keep a local preference model only for mail Resend does not manage (transactional, product-triggered lifecycle) or when consent records must live in the app database, and sync it to Contact Topics rather than running two sources of truth.
Before send:
- materialize/preview the Segment and recipient count;
- require role-based admin authorization and confirmation;
- create a campaign/run ID;
- send through a Broadcast to a Segment, scoped to a Topic, or enqueue one idempotent recipient job per Contact;
- filter preferences and suppression at send time (Resend skips unsubscribed and suppressed Contacts for Broadcasts; a custom queue must do it itself);
- record sent/skipped/failed counts without returning recipient PII broadly.
The Batch API sends up to 100 messages per call and does not support attachments (checked 2026-11-04). It suits multiple transactional messages. Resend directs marketing mail to Broadcasts, which handle queuing and throttling. Do not implement a long request loop with setTimeout as a campaign queue.
Webhooks and suppression
Verify Resend/Svix signatures using the raw request body and webhook secret before parsing/processing.
export async function POST(req: Request) {
const payload = await req.text();
let event;
try {
event = resend.webhooks.verify({
payload,
headers: {
id: req.headers.get('svix-id')!,
timestamp: req.headers.get('svix-timestamp')!,
signature: req.headers.get('svix-signature')!,
},
webhookSecret: process.env.RESEND_WEBHOOK_SECRET!,
});
} catch {
return new Response('Invalid signature', { status: 400 });
}
await processResendEventIdempotently(event);
return new Response('OK');
}
Use webhook/event ID for deduplication. data.to may contain multiple recipients; normalize addresses. Suppress hard bounces and complaints immediately, track transient delivery failures separately, and avoid equating a bounce with a user’s global marketing preference.
Preferences and unsubscribe
Model preferences by purpose, with a global marketing opt-out and a separate suppression state. Security and essential transactional messages should not be disabled by a marketing opt-out. For Broadcasts, Resend Topics are that per-purpose model; map product preferences onto them.
Broadcasts that include Resend's unsubscribe placeholder get a hosted unsubscribe flow. Resend states it adds the one-click headers to Broadcasts automatically (Resend blog, 9 Jan 2024, checked 2026-11-04); confirm on a test Broadcast by reading the received headers.
For marketing or subscribed mail sent through the /emails API, set both headers yourself:
List-Unsubscribe: <https://example.com/unsubscribe/{opaque-token}>
List-Unsubscribe-Post: List-Unsubscribe=One-Click
The URL must accept a POST with body List-Unsubscribe=One-Click and return 200 or 202 without login or confirmation, and serve the normal preferences page on GET. Stop mail within 48 hours of the request (checked 2026-11-04: Resend unsubscribe headers). Keep a visible unsubscribe link in the body as well.
Use an opaque, random or signed preference token that resolves server-side rather than placing raw email in the URL. Validate signatures in constant time, support key rotation/expiry policy, and provide a confirmation/preferences page.
Copy guidance
- State why the recipient is receiving the message.
- Keep subject lines factual; avoid false urgency or fabricated personalization.
- One primary action is usually enough.
- Re-engagement should mention a real product change or user state, not placeholders.
- Do not infer “power”, “churned”, or “inactive” solely from simplistic percentiles; define segments from product behavior and validate queries.
Verification
- Test
{ data, error }and thrown-error paths. - Confirm idempotency prevents duplicate logical sends.
- Verify HTML escaping, text rendering, sender, reply-to, and test recipient delivery.
- Test valid/invalid/replayed webhooks and multi-recipient payloads.
- Test bounce/complaint suppression and preference/unsubscribe paths, including a one-click
POSTthat succeeds without a session and a Topic opt-out that excludes the Contact from the next Broadcast. - Confirm SPF, DKIM, and DMARC pass with alignment in the headers of a delivered test message, and that marketing mail carries both unsubscribe headers.
- Test unauthorized campaign access, segment preview, duplicate run, retry, cancellation, and rate limits.
Sources checked 2026-11-04
- SDK: npm
resend6.37.0 - Contacts, Segments, Topics: https://resend.com/docs/dashboard/contacts/introduction , https://resend.com/docs/dashboard/contacts/manage-topics , https://resend.com/docs/dashboard/contacts/manage-segments
- Broadcasts: https://resend.com/docs/dashboard/broadcasts/introduction
- Unsubscribe handling: https://resend.com/docs/dashboard/contacts/managing-unsubscribe-list , https://resend.com/docs/dashboard/emails/add-unsubscribe-to-transactional-emails , https://resend.com/blog/gmail-and-yahoo-bulk-sending-requirements-for-2024
- Batch and idempotency: https://resend.com/docs/api-reference/emails/send-batch-emails
- Webhook verification: https://resend.com/docs/dashboard/webhooks/verify-webhooks-requests
- DMARC: https://resend.com/docs/dashboard/domains/dmarc
- Mailbox sender rules: the URLs in the table above
Claude app, ChatGPT and ZIP download
local coding agent required
This skill requires project files, terminal commands, and network access. Uploading it to a chat app does not provide equivalent execution.
ChatGPT Skills
This workflow needs a local coding environment or capabilities that a chat-only Skills upload does not provide.
Package details
- Package
- email-with-resend/SKILL.md
- Author
- @tushaarmehtaa
- Added
- 7 Mar 2026
- Tags