Node.js
Send an email from Node.js with the notix-js SDK.
Send your first email from Node.js with notix-js, the official SDK. It installs with npm, pnpm, yarn or bun.
Prerequisites
- An API key. Keep it on your server, never in a browser.
- A verified domain to send from.
Install the SDK
npm install notix-jspnpm add notix-jsyarn add notix-jsbun add notix-jsSet your API key
Put the key in your environment. The SDK reads
NOTIX_API_KEYwhen you do not pass a key to the constructor.NOTIX_API_KEY=notix_12345Send an email
import { Notix } from "notix-js"; const notix = new Notix(process.env.NOTIX_API_KEY); const { data, error } = await notix.emails.send({ from: "Acme <receipts@acme.com>", to: "maria@example.com", subject: "Your receipt for order 4471", html: "<p>Thanks for your order, Maria.</p>", text: "Thanks for your order, Maria.", });Check the response
Every SDK method returns
{ data, error }. It does not throw on an API error. On success,data.emailIdis the id every webhook event for this email refers to.if (error) { console.error(error.code, error.message); process.exit(1); } console.log("Sent", data?.emailId);error.codeis a stable code such asUNAUTHORIZEDorRATE_LIMITED. See Errors for the full list.
Next steps
- Send up to 100 emails in one call with batch sending.
- Add files with attachments.
- Make retries safe with idempotency keys. Pass
{ idempotencyKey: "order-4471-receipt" }as the second argument tosend. - Hear about deliveries and bounces with webhooks.
- See every field in Send an email.