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/nodeGet Up and Running in 3 Easy Steps
Install via npm, pnpm, or yarn
Run `npm install @mailofly/node` in your project. Full TypeScript declarations are bundled right in the package.
Initialize with your API key
Store your key securely in `process.env.MAILOFLY_API_KEY` and instantiate `new Mailofly({ apiKey })`.
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.
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);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()`.
Explore Mailofly Infrastructure Capabilities
Build resilient, high-deliverability email systems with our core developer tools.
Frequently Asked Questions about Node.js
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.