Send Next.js email from the server boundary you already have. Route Handler in, delivery event out.
Queue transactional mail without shipping credentials to the client, retain the accepted message ID, and trace delivery independently from the request.
✓Server-side only. Works in Route Handlers and Server Actions.
One request, complete trace
Request
POST /api/v1/emails
Authorization: Bearer aem_…
Idempotency-Key: welcome-8f21
{ "to": "[email protected]", "template": "welcome" }
202 Accepted
{ "id": "msg_7ca31", "status": "queued" }
[ 01 / 03 ]Integration shape
Keep email work on the server side of the App Router.
Use Route Handlers and Server Actions
Route Handlers give external callers an HTTP boundary; Server Actions work for trusted mutations initiated by your React tree.
Publish product events
Publish signup, trial, or payment events after the mutation succeeds, so lifecycle flows follow committed product state.
Verify the webhook
A Route Handler reading the raw body — Next gives you req.text() before any JSON parsing.
[ 02 / 03 ]Server quickstart
Queue one email from a Next.js Route Handler.
The route keeps the credential server-side, returns an accepted ID, and protects retries with an idempotency key.
Keep the credential in the server runtime. A 202 response means queued, not delivered.
export async function POST(request: Request) {
const { email, userId } = await request.json();
return fetch("https://sendandretain.com/api/v1/emails", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.AEM_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": `welcome-${userId}` },
body: JSON.stringify({ to: email, template: "welcome" }),
});
}Accepted response
{ "id": "msg_7ca31", "status": "queued" }[ 03 / 03 ]Related
Keep building with Next.js
Questions people ask us
Give your next Next.js email a return path.
Queue it from the server, keep the ID, and verify the delivery event when it arrives.