Official Node.js SDK•JavaScript / TypeScript Runtime

Send Transactional Emails with Node.js & TypeScript

A lightweight, modern Node.js client for sending transactional emails, managing bulk batches, and handling signed webhooks with zero friction.

npm install @mailofly/node
Setup Tutorial

Get Up and Running in 3 Easy Steps

01

Install via npm, pnpm, or yarn

Run `npm install @mailofly/node` in your project. Full TypeScript declarations are bundled right in the package.

02

Initialize with your API key

Store your key securely in `process.env.MAILOFLY_API_KEY` and instantiate `new Mailofly({ apiKey })`.

03

Dispatch transactional emails

Call `mailofly.emails.send()` with recipients, HTML/text body, attachments, tags, and custom metadata.

Production-Ready Code Example

Copy and paste into your project. Fully typed and tested.

send-email.ts
import { Mailofly } from "@mailofly/node";

const mailofly = new Mailofly({
  apiKey: process.env.MAILOFLY_API_KEY!,
});

async function run() {
  const result = await mailofly.emails.send({
    from: "Support Team <support@yourdomain.com>",
    to: ["customer@example.com"],
    subject: "Your Order Has Shipped! #94821",
    html: `
      <h2>Good news! Your order is on the way.</h2>
      <p>Tracking number: <strong>TRK-984210948</strong></p>
      <p>Carrier: FedEx Express</p>
    `,
    headers: {
      "X-Entity-Ref-ID": "order-94821",
    },
    tags: [
      { name: "environment", value: "production" },
      { name: "type", value: "shipping_update" },
    ],
  });

  console.log("Email dispatched successfully. Message ID:", result.id);
}

run().catch(console.error);
Why Developers Love It

Engineered for Node.js

Full TypeScript Autocomplete

Enjoy rich type definitions for all send parameters, webhook payloads, and API error codes.

Built-in Retries & Timeout Handling

Automated exponential backoff handles transient network glitches without crashing your server.

Batch Dispatch API

Send up to 500 personalized emails in a single HTTP request using `mailofly.emails.sendBatch()`.

Got Questions?

Frequently Asked Questions about Node.js

Yes. You can attach PDF receipts, invoices, and images by passing an array of attachments with `filename` and base64 `content` or a public URL.

Start Sending from Node.js in Minutes

3,000 free emails every month. Copy your API key, run the code snippet, and watch your delivery logs in real time.