Send emails with Node.js
Transactional and marketing email from TypeScript or JavaScript. One fetch call, and a message ID you can follow to the inbox.
✓Free to start. Unlimited contacts on every tier.
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 / 04 ]Quickstart
How do I send email with Node.js?
Three steps from no account to a queued email. The built-in fetch is enough.
Create an API key
In the dashboard, open Settings → API & MCP and create a key with the Send + manage permission (the default). It starts with aem_ and is shown once.
Store it as an environment variable
Keep the key on your server, never in browser code. Your code reads it from process.env.AEM_KEY.
.envAEM_KEY=aem_...Send the email
POST the recipient and a published template. A retry with the same Idempotency-Key won't send a second email.
send-welcome.mjsconst response = await fetch("https://sendandretain.com/api/v1/emails", { method: "POST", headers: { Authorization: `Bearer ${process.env.AEM_KEY}`, "Content-Type": "application/json", "Idempotency-Key": `welcome-${user.id}` }, body: JSON.stringify({ to: user.email, template: "welcome" }), }); if (!response.ok) throw new Error(await response.text());Keep the message ID
A 202 means queued, not delivered. Store the id; delivery, bounce, and complaint events arrive later on your signed webhook.
202 Accepted{ "id": "msg_7ca31", "status": "queued" }
[ 02 / 04 ]In production
What does a production Node.js integration need?
Server-side only
Call from a route handler, a server action, or a worker. The key never reaches the browser.
Retries with the same key
Send after your database write commits. Retry timeouts and 5xx errors with the same Idempotency-Key; don't retry validation or auth errors.
Webhooks checked on the raw body
Verify the signature on the raw request body before any JSON parsing touches it.
Events for marketing email
Send product events like signup or trial started. Automations you've turned on decide which email goes out.
[ 03 / 04 ]Example prompts
What can you ask your coding agent to do in Node.js?
Paste these into Claude Code, Cursor, or Codex. Connect the MCP server and it can build the templates and automations too.
Welcome email
“Find where we create users and send a welcome email with the Send & Retain API. Read the key from AEM_KEY and use the user ID as the idempotency key.”
Receipt
“Add a receipt email to our checkout with the Send & Retain API. Send it only after the order is saved, keyed on the order ID.”
Webhooks
“Add an Express route that verifies Send & Retain webhook signatures on the raw body and flags bounced addresses in our users table.”
Trial automation
“Send a trial_started event to Send & Retain when a trial begins, then build a paused trial automation for it.”
[ 04 / 04 ]Related
More ways to send email with Node.js
Questions people ask us
Send your first email with Node.js.
Create a key, make one call, and follow the message ID to the inbox.