Guide
How to send email with Node.js
Send email from any Node.js app with the typed SDK or plain fetch.
In short
Create a Sendpository account, verify your domain, put your API key inSENDPOSITORY_API_KEY, and send with the code below - one HTTPS request per email, from server-side code only.1. Verify your sending domain
Add your domain in the dashboard and publish the three DNS records it shows - SPF and a bounce record on an sp. subdomain, and a DKIM key on your apex. Your existing records are never edited. Verification usually lands in a few minutes, and you can set up the code below while you wait.
2. Create a key
Create an API key with the sending permission. It is shown once, so put it straight into your secrets. Read the key from process.env.SENDPOSITORY_API_KEY.
3. Install
npm install sendpository
4. Send an email
import { Sendpository } from "sendpository";
const sendpository = new Sendpository(process.env.SENDPOSITORY_API_KEY);
const { id } = await sendpository.emails.send({
from: "Your App <hello@mail.yourdomain.com>",
to: ["customer@example.com"],
subject: "Your receipt",
html: "<p>Thanks for your order.</p>",
});
console.log("queued", id);A success returns { "id": "..." } - the message’s id for looking it up later. A failure returns { "error": { "type", "message" } } with a 4xx or 5xx status.
Where the send belongs
Anywhere on the server, but not in the request path if the caller is waiting on it. Resolve the HTTP response first and send afterwards, or push the job onto whatever queue you already run.
Create one client at module scope and reuse it. Constructing an SDK instance per request builds a new connection pool each time and loses keep-alive between calls.
Testing it
- Run with `node --env-file=.env send.mjs` on Node 20+ so the key comes from the file rather than your shell history.
- An invalid key returns a 401 with `authentication_error` as the `type`. Branch on that field, never on the message text, which is written for humans and changes.
Things to know
- The SDK retries rate limits and 5xx responses, and exposes typed errors - branch on error.type.
- Pass an idempotencyKey when a job can retry, so a replay never sends twice.
- No SDK wanted? The API is JSON over HTTPS; the fetch example on the Express guide works anywhere.
Questions
Should I create a new client for each send?
No. Build one at module scope and reuse it. A new instance per request creates a new connection pool each time, so every send pays a fresh TLS handshake instead of reusing a warm connection.
How do I send email with Node.js?
Verify your sending domain, create an API key, put it in an environment variable, and POST the message as JSON to https://api.sendpository.com/v1/emails from server-side Node.js code. The example on this page runs as written once the domain is verified.
Can I send email with Node.js without SMTP?
Yes. This is plain HTTPS, so Node.js needs no mail library and no SMTP port - which matters on hosts that block outbound 25 and 587. Failures come back as a status code on the call instead of as a bounce message hours later.
More guides
Send email with Next.js
Send transactional email from a Next.js App Router server action or route handler.
Send email with Express
Send email from an Express route with fetch - no SDK needed.
Send your first email in minutes
6,000 emails a month (up to 200 a day), free forever. No card needed.