Skip to main content
Add welcome, password reset, and receipt emails to a Next.js App Router app by calling Courier’s client.send.message from server code. Courier delivers them through Resend and adds SMS, push, and in-app when you need them.
Save it as first-send.mts, then run it with your API key and email address:
It prints a request id that you’ll find in Courier Logs. On a Test key, use your Courier login address. Test email reaches it with no provider connected.

courier-nextjs-email-quickstart

The finished Next.js app from this guide, ready to clone and run.

Build this with a coding agent

To have a coding agent add Courier to your Next.js app, paste this prompt into Claude Code, Cursor, or Codex from the project root:
Install the Courier skill with npx skills add trycourier/courier-skills, and connect the Courier MCP server so the agent can check Courier Logs and templates itself.

Rules for AI agents

  • Use @trycourier/courier through lib/courier.ts, which keeps import "server-only". Only the standalone scripts/send.ts builds its own client.
  • Read COURIER_API_KEY from the environment on the server. Never import the client into a client component.
  • Pass an "Idempotency-Key" on resets and receipts: password-reset-${resetId} for a reset, Stripe’s event.id for a receipt.
  • Send from the server action or route handler that owns the event. Verify the Stripe signature before sending a receipt.
  • Build reset links from APP_URL, never from the request’s Host header.
  • Never call Resend directly. Courier routes the email channel to it.

What you’ll build

This Next.js 16 App Router app sends three emails, each one client.send.message call from @trycourier/courier:
  • A welcome email from the signUp server action
  • A password reset email from POST /api/password-reset
  • A receipt email from POST /api/stripe, on invoice.payment_succeeded

Prerequisites

For the first send

For the full build

Clone the finished Next.js app

Clone the Courier Next.js quickstart to run the finished app with your own key:
The steps below add or change these files:

Install the Courier Node SDK in your Next.js app

Install the Courier Node SDK, @trycourier/courier, in your Next.js app with server-only and stripe:
Add your keys to .env.local, as in the repo’s .env.example:

Create a server-only Courier client for Next.js

lib/courier.ts gives every Next.js route one Courier client that stays on the server.
lib/courier.ts

Send a welcome email from a Next.js server action

The Next.js signUp server action sends the welcome email through Courier.
app/actions.ts
Post a form to it from a page:
app/page.tsx

Send a password reset email from a Next.js route handler

The Next.js route handler emails a one-time reset link through Courier, with one idempotency key per reset.
app/api/password-reset/route.ts

Send a receipt email from a Stripe webhook in Next.js

The Next.js Stripe webhook route verifies the event, then sends a receipt through Courier keyed by the event id.
app/api/stripe/route.ts

Add a test send script

scripts/send.ts sends the welcome email from the command line, so you can check your key and Resend before wiring up a form. server-only resolves only inside Next.js, so the script builds its own client. Add its tools and an npm run send script:
scripts/send.ts

Verify

Send each Next.js email once, then find it in Courier Logs:
  1. Run npm run send. It prints a request id.
  2. Run npm run dev, open localhost:3000, and sign up with your email.
  3. Request a reset for your DEMO_EMAIL address. The route answers {"ok":true} either way, so check Logs: curl -X POST localhost:3000/api/password-reset -H "Content-Type: application/json" -d '{"email": "YOUR_DEMO_EMAIL"}'
  4. Run stripe listen --forward-to localhost:3000/api/stripe, put its whsec_ secret in .env.local, restart, then stripe trigger invoice.payment_succeeded --override customer:email=YOUR_EMAIL

Go to production with Courier

Courier is notification infrastructure for humans and AI agents. In a Next.js app it sends through Resend. Go live covers moving from Test to Production:
  • Use a Production key, with Resend connected in Production.
  • Record processed Stripe event ids. Stripe retries for three days, past Courier’s 25-hour idempotency window (Stripe guide).
  • Put resets and receipts on a REQUIRED topic so preferences never block them.

FAQ

Resend stays your email provider when you add Courier. Connect the Resend integration, and Courier sends every email through it.
A password reset sends once per "Idempotency-Key", which covers retries for 25 hours. A second form submit is a new reset, so return early when the user has an unexpired one.
A Next.js server action runs on the server, so it can call Courier’s client.send.message from a module marked import "server-only".
Courier adds a channel through the send’s routing. Connect an SMS provider or the Courier Inbox, then list it: method: "single" falls back in order, and method: "all" sends on every channel.