---
name: build-transactional-email-with-resend
description: Sends welcome, password-reset and order-receipt mail through Resend, using React Email templates, after a server event. Use this when the user wants a sign-up email, a reset link, a receipt, or transactional mail that is not a contact form.
license: CC-BY-4.0
compatibility: Needs a Resend account, a verified sending domain, and Node 20+.
metadata:
  category: backend
  tags: "email,react"
  author: johnny-bravo
  version: "1.0"
  updated: "2026-11-16"
  status: published
  aliases: "send-transactional-email-with-resend"
---

# Build transactional email with Resend

These messages are triggered by your server: an account was created, a reset was requested, or an order was paid. They are not a form that visitors fill in to reach you. For that, use build-contact-form-with-email.

## When to use
- You need a welcome message after sign-up.
- You issue your own password-reset link and must email it.
- You need a receipt after payment, with the order id and total.

## When not to use
- The message is an enquiry from a contact form to the site owner.
- Supabase Auth or Clerk already sends the reset mail. Do not send a second one.

## Steps
1. Verify the sending domain in Resend and add the DNS records it shows. Production mail uses that domain, not the shared test sender.
2. Install `resend` and `react-email`. Put `RESEND_API_KEY` in `.env.local` and on the host. Never prefix it with `NEXT_PUBLIC_`.
3. Write one template per message under something like `emails/`: welcome, reset, receipt. Import layout pieces from `react-email`. Pass props in. Do not query the database inside the template.
4. Send only from a server route, server action or webhook. Pass the template as a function call, `WelcomeEmail({ name, url })`, not as JSX. Branch on `{ data, error }`.
5. Pass `idempotencyKey` as the second argument, shaped like `welcome-user/${userId}` or `receipt/${orderId}`. A key placed inside the email object is dropped, and a retry can send twice. Keys last 24 hours and must be 1 to 256 characters.
6. Welcome: send once when the account row exists. Reset: only if your app created the token. Store a hash of the token, make the link single-use, and expire it within an hour. Use the same reply whether or not the address is registered.
7. Receipt: send from the paid webhook, after the order is stored. Include the order id, the line items and the total. Never include the full card number.
8. Include a plain-text part as well as HTML. Preview the templates before they go to a real inbox.

```ts
const { data, error } = await resend.emails.send(
  {
    from: "Shop <receipts@your-domain.com>",
    to: [customerEmail],
    subject: `Receipt ${orderId}`,
    react: ReceiptEmail({ orderId, items, total }),
  },
  { idempotencyKey: `receipt/${orderId}` },
);
```

## Gotchas
- `onboarding@resend.dev` is a test sender. Mail from it will not stand in for your domain in production.
- The React prop must be a function call. JSX here is a common reason the send fails types.
- A webhook that retries without an idempotency key emails the buyer again.
- Reset links in HTML and in logs are secrets. Do not log the rendered message.

## Safety
- The API key stays in the server environment. Do not paste it into chat, a screenshot or the repo.
- A reset token and a full receipt are personal data. Send them only to the address on the account or the order.

## Portability
Works with any framework that can run the Resend Node SDK. If you use another email provider instead of Resend, keep the same split: React templates, a server-only send, and an idempotency key per event. If you are not on React, send HTML you rendered yourself and keep the trigger rules.

## Example prompt
"Send a one-time receipt with Resend and React Email after the order is paid. Do not email twice on webhook retries."

## Done when
- Welcome, reset and receipt each have a template and a server trigger.
- A repeated webhook with the same idempotency key does not send a second receipt.
- The API key is not in client code, and the reset email does not reveal whether the account exists.

---
House original by TheSkillVault (CC-BY-4.0).
