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

  1. Install the SDK

    npm install notix-js
    
  2. Set your API key

    Put the key in your environment. The SDK reads NOTIX_API_KEY when you do not pass a key to the constructor.

    NOTIX_API_KEY=notix_12345
    
  3. Send 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.",
    });
    
  4. Check the response

    Every SDK method returns { data, error }. It does not throw on an API error. On success, data.emailId is 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.code is a stable code such as UNAUTHORIZED or RATE_LIMITED. See Errors for the full list.

Next steps

Open in ClaudeOpen in ChatGPT