Skip to main content

Node.js SDK

The jetemail package is the official Node.js SDK for JetEmail transactional email (MIT license, Node.js 18+, uses native fetch, no runtime dependencies). Create a transactional API key in the dashboard: Outbound → Keys → Add API key. Use that key with the SDK.

Installation

Package on npm: jetemail. The package ships TypeScript types and both ESM (import) and CommonJS (require) builds.

Quick start

In CommonJS projects, use const { JetEmail } = require('jetemail'); instead of the import. Use a from address on a verified domain (see Getting started).

Constructor

The constructor throws an Error if apiKey is missing. The client exposes two services:

client.email.send(options)

Send a single email. Options use the same field names as the REST API (snake_case, e.g. reply_to).
Response shape: { id: string; response: string }. The SDK validates from, to, subject, and html/text locally before making the request and throws a plain Error if any is missing (see Error handling).

client.batch.send(emails)

Send up to 100 emails in one request. Each element uses the same fields as a single send. Returns summary (total, successful, failed) and results per message (success with id and response, or error with error and the original email).
An empty array, more than 100 emails, or an invalid email in the array throws a plain Error before any request is made.

Error handling

API errors throw JetEmailError, which has statusCode (HTTP status), message, and response (the parsed error body, { message?: string; error?: string }, when the API returned JSON).
Client-side validation failures (missing required fields, an empty or oversized batch, or a missing apiKey) throw a plain Error rather than JetEmailError. Network failures from fetch are not wrapped and surface as-is. Common status codes: 400 invalid request, 401 bad/missing API key, 500 server error.

TypeScript

Exported types: JetEmail, JetEmailConfig, SendEmailOptions, SendEmailResponse, SendBatchResponse, BatchEmailResult, BatchEmailSuccess, BatchEmailError, Attachment, EmailHeaders, EmailRecipient, JetEmailError, plus the Emails and Batch service classes.
For additional examples, see the README on npm. REST details: API reference.