---
title: Nightmail
description: Send through Nightmail's email API on Amazon SES with native idempotency, scheduling, attachments, and signed inbound webhooks.
sidebar:
  icon: "https://www.google.com/s2/favicons?domain=nightmail.dev&sz=64"
lastModified: 2026-11-29
---

## Capabilities

| Repeated headers | Idempotency | Scheduling | Personalized |
| ---------------- | ----------- | ---------- | ------------ |
| No               | `native`    | Yes        | `expanded`   |

These values come from the adapter's exported `capabilities` declaration. The [field support matrix](/docs/adapters/field-support) covers normalized message fields.

The Nightmail adapter calls `POST /v1/emails/send` with plain `fetch` and Bearer authentication. [Nightmail](https://nightmail.dev) is an email API on Amazon SES that sends, receives, and replies on your own domains. A `202` response means Nightmail queued the message, not that it was delivered.



**[Nightmail](https://nightmail.dev)** · `@opencoredev/email-sdk/nightmail` · [setup guide](/docs/adapters/nightmail)



:::note
`@opencoredev/email-sdk/nightmail` is not in a published release yet. It ships in the next release after 3.1.0, so `npm install @opencoredev/email-sdk@3.1.0` does not include it.
:::

## Configure

Verify a sending domain in Nightmail, then create an API key. A Send only key restricted to that domain is enough to send.

```ts title="lib/email.ts"
import { createEmailClient } from "@opencoredev/email-sdk";
import { nightmail } from "@opencoredev/email-sdk/nightmail";

export const email = createEmailClient({
  adapters: [nightmail({ apiKey: process.env.NIGHTMAIL_API_KEY! })],
});
```

| Prop | Type | Default | Description |
| - | - | - | - |
| `apiKey` | `string` | - | Nightmail API key. |
| `baseUrl?` | `string` | `"https://nightmail.dev"` | Override the API base URL. Self-hosted installations pass their own public URL. |
| `headers?` | `Record<string, string>` | - | Extra request headers sent with every call. |
| `fetch?` | `typeof fetch` | - | Custom fetch implementation for tests or special runtimes. |

:::info[Testing without a real inbox]
Send to `success@simulator.amazonses.com` (or `bounce@`, `complaint@`, `ooto@`, and
`suppressionlist@` the same domain) to exercise each outcome. Simulator sends count against your
daily sending limit but not your sender score.
:::

## Send

The adapter maps `cc`, `bcc`, `replyTo`, custom `headers`, `attachments`, and `sendAt`. The sender's display name goes out as Nightmail's `fromName`; `sendAt` goes out as `scheduledAt` in UTC.

```ts
const result = await email.send({
  from: "Acme <hello@acme.com>",
  to: "user@example.com",
  replyTo: "support@acme.com",
  subject: "Your invoice is ready",
  html: "<p>Your March invoice is attached.</p>",
  attachments: [{ filename: "invoice.pdf", content: pdfBytes, contentType: "application/pdf" }],
  sendAt: "2026-12-01T09:00:00Z",
});

console.log(result.id); // Nightmail email id
```

Nightmail's send takes attachment IDs, so the adapter uploads each attachment to `POST /v1/attachments` first, one request per file, and sends the returned IDs. An attachment is uploaded as inline when it has a `contentId` or `disposition: "inline"`. If an upload fails, the email is never submitted and the error reports `delivery: "not_sent"`.

Nightmail has no tags or metadata fields, so a message with `tags` or `metadata` throws an `EmailValidationError` before any request is made.

:::warning[Limits checked before sending]
Recipient and `replyTo` addresses must be plain email addresses, because Nightmail rejects
display names there. A message can have at most 50 `to`, 49 `cc`, and 49 `bcc` recipients, 10
`replyTo` addresses, 15 custom headers, and 100 attachments. Each of these throws an
`EmailValidationError` before any request is made.
:::

### Idempotency

The client's idempotency key goes out as the `Idempotency-Key` header. Nightmail accepts keys of 1 to 200 printable ASCII characters; any other key, such as a long per-recipient key from `sendPersonalized`, is hashed to a SHA-256 digest, so the same client key always maps to the same Nightmail key.

Each attachment upload gets its own key derived from the send's key. A retried send therefore replays the same uploads, gets the same attachment IDs, and sends the same body, so Nightmail replays the first result instead of answering `409 IDEMPOTENCY_CONFLICT`.

### Failed sends

Nightmail checks validation, suppression, balance, sending limits, and content screening before it queues a message, so a 4xx response, including a `429` for a rate, ramp, or built-in domain limit, reports `delivery: "not_sent"`. A `408`, a `409` (a request with the same key still in flight, or a key reused with a different body), and 5xx responses report `delivery: "unknown"`. The error message includes Nightmail's `error.code` and `requestId`, and `retryable` follows the `retryable` flag in Nightmail's error body.

## Receive

Nightmail signs every webhook delivery in the Standard Webhooks format (`webhook-id`, `webhook-timestamp`, `webhook-signature`). Create the inbound webhook with `format: "inbound"`, whose body is an `email.received` event carrying the parsed message and, when the whole body fits Nightmail's 512 KiB webhook limit, the original MIME.

```ts title="app/api/inbound/route.ts"
import { handleInbound } from "@opencoredev/email-sdk/inbound";

export async function POST(request: Request) {
  const result = await handleInbound(request, {
    provider: "nightmail",
    secret: process.env.NIGHTMAIL_WEBHOOK_SECRET!,
  });

  if (result.type === "handshake") return result.response;

  for (const email of result.emails) console.log(email.from?.address, email.subject);

  return new Response(null, { status: 200 });
}
```

The parser reads the inlined MIME when it is present. A larger message falls back to Nightmail's parsed text, HTML, headers, and attachment metadata. Nightmail caps text and HTML at 256 KiB together and drops them and the headers when the event still does not fit, so check `email.truncated` before treating the message as complete; `email.messageUrl` is Nightmail's API URL for the full message. The attachments carry Nightmail's `downloadUrl` in `url`, which needs a key that can read the message, such as an inbound key scoped to the receiving address. Nightmail's default thin `nightmail` format carries only IDs, so the parser rejects it. See [Receive email](/docs/guides/receive-email) for the full flow.

## Verify from the CLI

```bash
NIGHTMAIL_API_KEY="..." npx --package @opencoredev/email-sdk email-sdk doctor --adapter nightmail --live
```

The live check reads `GET /v1/me`, which describes the calling key. Nothing is sent. It probes hosted Nightmail only; a self-hosted `baseUrl` works for sends but not for `doctor --live` or `bun run live:nightmail`.

```bash
NIGHTMAIL_API_KEY="..." npx --package @opencoredev/email-sdk email-sdk send \
  --adapter nightmail \
  --from "Acme <hello@acme.com>" \
  --to success@simulator.amazonses.com \
  --subject "Nightmail smoke test" \
  --html "<p>It works</p>" \
  --dry-run
```

Drop `--dry-run` to send for real. The CLI also reads `NIGHTMAIL_BASE_URL` from the environment.

{/* adapter-faq:start (generated by scripts/generate-adapter-faq.ts) */}

## Frequently asked questions

### Does Email SDK support Nightmail?

Yes. Email SDK ships a Nightmail adapter imported from @opencoredev/email-sdk/nightmail. You keep your Nightmail account and credentials; the SDK adds message validation, typed errors, and no-network test adapters around the same send() call used for every other provider.

### Which message fields does the Nightmail adapter support?

Nightmail supports CC recipients, BCC recipients, Reply-To address, Custom headers, Attachments, and Scheduled sending (sendAt). It does not support Tags and Metadata; Email SDK rejects a message that uses those fields before any request is made.

### Can Nightmail schedule email for later with Email SDK?

Yes. Set sendAt on the message and the Nightmail adapter passes the scheduled time to the provider.

### Does the Nightmail adapter support idempotent sends?

Yes. The Nightmail adapter passes an idempotency key to the provider, so Nightmail deduplicates repeated sends on its side.

{/* adapter-faq:end */}
