Send email with Node.js

The plain Node path: one dependency, or none at all with fetch.

You need a verified sending domain and an API key from Settings › API Keys. If neither exists yet, the quickstart covers both in a couple of minutes.

Install

npm i sending-sdk

Send

import { Sending } from "sending-sdk";
 
const sending = new Sending({ apiKey: process.env.SENDING_API_KEY });
 
const { id } = await sending.emails.send({
  from: "Acme <[email protected]>",
  to: "[email protected]",
  subject: "Welcome",
  html: "<p>You're in.</p>",
  idempotencyKey: "welcome-sara-001",
});
console.log(id);

A successful call answers 202 with the message id: accepted and queued, not yet delivered. Delivery, opens, bounces and complaints arrive later, on webhooks or in the dashboard.

What changes in Node.js

Node 18 and up have fetch built in, so the SDK is a convenience rather than a requirement: the REST call is one POST with a JSON body.

The thing that catches people

The idempotency key goes in the body, not in an Idempotency-Key header. Providers differ here, and this is the single most common 422 for people arriving from another API.

Next

  • All the fields: cc and bcc, reply-to, attachments, templates, scheduling.
  • Webhooks: delivery, bounce and complaint events, signed with HMAC.
  • Domains: SPF, DKIM and MAIL FROM, and why sending is refused until they are in place.
  • MCP: the same operations as tools, when the one writing the code is an agent.

Nearby: JavaScript and TypeScript

All 30 stacks