Skip to content

Send transactional email from Node.js

Add password resets, receipts, invites, and alerts to any Node.js backend with the official Loops SDK. The same code runs in Express, Fastify, queue workers, cron jobs, and plain scripts.

How a send works

This guide takes a Node.js backend from npm install to a delivered email, without tying the code to a framework. Every send is one API call from your server.

Your app
Password reset requested
one API call
Send transactional
Password reset
no tracking pixels
Your domain
Verified sender
sent as you
Delivered
Inbox
see every send
Each transactional email goes to one person, right after they act.

If you add marketing or lifecycle email later, the same Loops account and contact record handle that too.

Give this to your agent

Using Claude Code, Cursor, or Codex? Paste this prompt into the repository. It covers the setup, first send, retry policy, and duplicate protection.

Add transactional email to this Node.js app with Loops (loops.so).
Run npm install loops. Create lib/loops.ts with a server-side
LoopsClient using LOOPS_API_KEY. Add sendPasswordReset(email,
resetUrl, idempotencyKey) using sendTransactionalEmail,
LOOPS_PASSWORD_RESET_TRANSACTIONAL_ID, and the Idempotency-Key
header. Retry only 429 and 5xx errors with exponential backoff.
Reuse the same idempotency key for every attempt. Add the required
variables to .env.example. Docs: https://loops.so/docs/sdks/javascript
and https://loops.so/docs/transactional

Install the SDK

npm install loops

The package is loops. Version 7 supports TypeScript, ESM, and CommonJS, uses native fetch, and requires Node 18 or later. Keep the client in server code because the API key grants account access.

// lib/loops.ts
import { LoopsClient } from "loops";

if (!process.env.LOOPS_API_KEY) {
  throw new Error("LOOPS_API_KEY is not set");
}

export const loops = new LoopsClient(process.env.LOOPS_API_KEY);

Generate a key under Settings → API in Loops. Store it in your deployment environment and never expose it to browser code, mobile apps, logs, or a committed file.

# .env
LOOPS_API_KEY=
LOOPS_PASSWORD_RESET_TRANSACTIONAL_ID=

Send your first email

Create a transactional email in Loops, add a {resetUrl} data variable, and publish it. Copy the transactional ID from the API details on the Publish page.

import { loops } from "./lib/loops";

export async function sendPasswordReset(email: string, resetUrl: string) {
  return loops.sendTransactionalEmail({
    transactionalId: process.env.LOOPS_PASSWORD_RESET_TRANSACTIONAL_ID!,
    email,
    dataVariables: { resetUrl },
  });
}

This calls POST /api/v1/transactional. Every required data variable must be present and its name is case-sensitive. The recipient does not need to be in your Audience. Add addToAudience: true only when you also want to create a marketing contact.

Do not use addToAudience as a shortcut for consent. Loops double opt-in currently applies to Form endpoints, not transactional sends or contact API calls. Use the double opt-in form flow when a new marketing contact must confirm. Product behavior rechecked September 2, 2026.

Retry safely with idempotency

import { APIError, RateLimitExceededError } from "loops";
import { loops } from "./lib/loops";

type SendInput = Parameters<typeof loops.sendTransactionalEmail>[0];

export async function sendWithRetry(
  input: SendInput,
  idempotencyKey: string,
  attempts = 3,
) {
  for (let attempt = 0; attempt < attempts; attempt++) {
    try {
      return await loops.sendTransactionalEmail({
        ...input,
        headers: { "Idempotency-Key": idempotencyKey },
      });
    } catch (error) {
      const retryable =
        error instanceof RateLimitExceededError ||
        (error instanceof APIError && error.statusCode >= 500);

      if (!retryable || attempt === attempts - 1) throw error;
      await new Promise(resolve => setTimeout(resolve, 500 * 2 ** attempt));
    }
  }
}

Loops allows 10 API requests per second per team. Retry only 429 and 5xx responses. Generate one idempotency key for the business event, persist it, and reuse it for every attempt. A repeated key returns 409 for 24 hours instead of sending the email twice. Treat a 409 as a conflict to inspect: it can also mean the key was reused with a different request body.

One password reset, one keyIdempotency-Key: reset-8421
0.0 sPOSTFirst attempt429 Too many requests
0.5 sPOSTSame key, after waiting 0.5 s429 Too many requests
1.5 sPOSTSame key, after waiting 1 s200 Sent
An hour later the job runs again
1 hPOSTSame key409 Conflict, nothing sent
Ruled out a new key on each attempt
POSTNew key after the 429Two resets in one inbox
Retry 429 and 5xx with the same key. A 409 means that key already sent.

Test without sending real email

Send to an address at example.com or test.com first. Loops returns a normal success response but does not deliver to those reserved domains. Then send to your own inbox, confirm the record under Transactional → Metrics, remove one required data variable to verify the 4xx path, and run npx tsc --noEmit.

Common failure modes

Check these first when a send fails.

What went wrongFix
Wrong packageInstall loops, not loops-js or another similar name.
API key in browser codeKeep the client on the server. The key grants account access.
Unpublished emailPublish it first. Drafts don’t send.
Missing dataSend every required data variable. Names are case-sensitive.
Duplicate emailReuse one Idempotency-Key for every retry of the same event.
Burst trafficCatch RateLimitExceededError and back off. The limit is 10 requests per second per team.

Keep transactional email transactional

Password resets, receipts, verifications, and security alerts can send regardless of subscription status, so keep them free of promotion. Read transactional email on Loops for the category boundary, or use product and lifecycle email for onboarding, trial, and win-back messages.

Common questions

Can I send transactional email from any Node.js framework?

Yes. The Loops JavaScript SDK works in Express, Fastify, workers, cron jobs, and plain Node.js scripts. It requires Node 18 or later and must run server-side.

How do I prevent duplicate transactional emails?

Send an Idempotency-Key header with a value that is unique to the business event, then reuse that same key for every retry. Loops returns 409 instead of sending the email again when a key was used in the previous 24 hours.

Which API errors should I retry?

Retry 429 rate-limit responses and 5xx server errors with exponential backoff. Do not retry ordinary 4xx errors such as a missing transactional ID, unpublished template, invalid email, or missing data variable until the request is fixed.

What's next

More on sending transactional email.

See all guides