> ## Documentation Index
> Fetch the complete documentation index at: https://jetemail.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Node.js

> Official jetemail npm package for transactional email

# Node.js SDK

The **[jetemail](https://www.npmjs.com/package/jetemail)** package is the official Node.js SDK for JetEmail transactional email (MIT license, **Node.js 18+**, uses native `fetch`).

Create a **transactional** API key in the dashboard: **Outbound** → **Keys** → Add API key. Use that key with the SDK.

## Installation

```bash theme={null}
npm install jetemail
```

Package on npm: [jetemail](https://www.npmjs.com/package/jetemail).

## Quick start

```ts theme={null}
import { JetEmail } from 'jetemail';

const client = new JetEmail('your-transactional-api-key');

await client.email.send({
  from: 'Your App <hello@yourdomain.com>',
  to: 'user@example.com',
  subject: 'Welcome!',
  html: '<h1>Welcome!</h1>'
});
```

Use a `from` address on a **verified domain** (see [Getting started](/transactional-email/getting-started)).

## Constructor

```ts theme={null}
// API key string
const client = new JetEmail('your-transactional-api-key');

// Or with options
const client = new JetEmail({
  apiKey: 'your-transactional-api-key',
  baseUrl: 'https://api.jetemail.com' // optional
});
```

## `client.email.send(options)`

Send a single email.

| Field                   | Required | Description                              |
| ----------------------- | -------- | ---------------------------------------- |
| `from`                  | ✓        | Sender, e.g. `"Name <email@domain.com>"` |
| `to`                    | ✓        | Recipient(s), string or array (max 50)   |
| `subject`               | ✓        | Subject line                             |
| `html`                  | \*       | HTML body (need `html` and/or `text`)    |
| `text`                  | \*       | Plain text (need `html` and/or `text`)   |
| `cc`, `bcc`, `reply_to` |          | Recipients (max 50 each)                 |
| `headers`               |          | Custom headers                           |
| `attachments`           |          | Attachments (max 40MB total)             |

Response shape: `{ id: string; response: string }`.

## `client.batch.send(emails)`

Send up to **100** emails in one request. Returns `summary` (`total`, `successful`, `failed`) and `results` per message (success with `id`, or error with `error`).

## Error handling

```ts theme={null}
import { JetEmail, JetEmailError } from 'jetemail';

try {
  await client.email.send({ /* ... */ });
} catch (error) {
  if (error instanceof JetEmailError) {
    console.error(error.statusCode, error.message, error.response);
  } else {
    throw error;
  }
}
```

Common status codes: **400** invalid request, **401** bad/missing API key, **500** server error.

## TypeScript

Exported types include `JetEmail`, `SendEmailOptions`, `SendEmailResponse`, `SendBatchResponse`, `JetEmailError`, `Attachment`.

***

For batch examples, attachments (base64), custom headers, and the full option list, see the **[README on npm](https://www.npmjs.com/package/jetemail)**. REST details: [API reference](/api-reference/introduction).
