# Nightmail

> Nightmail is an email API on Amazon SES: send, receive and reply on your own domains.

To use Nightmail for someone, follow the Quickstart and “Give a coding agent its own key” in https://nightmail.dev/docs.md: you get your own API key when that person approves you from their Nightmail account.

Hosted Nightmail charges $0.20 per 1,000 emails, sent or received, after 5,000 sent and 20,000 received free every month. Contacts and teammates: no charge.

## Product and pricing

- [Nightmail](https://nightmail.dev/index.md): what it does and what it costs
- [Price calculator](https://nightmail.dev/pricing.md): Nightmail beside Resend, SendGrid, Postmark, Mailgun, Mailjet, Mandrill, Bird, MailerSend, Mailtrap, SMTP2GO, AhaSend, SocketLabs, MailPace, UniOne, MailChannels, Mailchimp, beehiiv, MailerLite, Buttondown, EmailOctopus, Ghost(Pro), AWeber, Loops and Brevo at three sizes, and how to price any other
- [The website in full](https://nightmail.dev/llms-full.txt): these pages and every comparison, in one file
- [Compare](https://nightmail.dev/compare.md): What a month costs on Nightmail and on 16 developer email APIs, 9 newsletter and marketing services, 9 services for agent inboxes, at three sizes each, read 25–26 Nov 2026.

## What other email services cost

- [SendGrid pricing](https://nightmail.dev/pricing/sendgrid.md): Nightmail $9. SendGrid $19.95. Per 50,000 emails a month · checked 25 Nov 2026. From $19.95 a month for 50,000 emails (Essentials) to $1,099 for 2,500,000 emails (Pro); above that, Premier, custom pricing. List prices before tax (twilio.com, 25 Nov 2026).
- [Resend pricing](https://nightmail.dev/pricing/resend.md): Nightmail $9. Resend $20. Per 50,000 emails a month · checked 25 Nov 2026. From $20 a month for 50,000 emails (Pro) to $1,150 for 2,500,000 emails (Scale); above that, Enterprise, custom pricing. List prices before tax (resend.com, 25 Nov 2026).
- [Mailchimp pricing](https://nightmail.dev/pricing/mailchimp.md): Nightmail $19. Mailchimp $270. Per 25,000 contacts, 100,000 emails a month · checked 25 Nov 2026. From $13 a month for 500 contacts (Essentials) to $800 for 100,000 contacts (Standard), the largest size read here. List prices before tax (mailchimp.com, 25 Nov 2026).
- [Mailgun pricing](https://nightmail.dev/pricing/mailgun.md): Nightmail $1. Mailgun $15. Per 10,000 emails a month · checked 25 Nov 2026. From $15 a month for 10,000 emails (Basic) to $1,250 for 2,500,000 emails (Scale); above that, Enterprise, price on request. List prices before tax (mailgun.com, 25 Nov 2026).
- [Postmark pricing](https://nightmail.dev/pricing/postmark.md): Nightmail $1. Postmark $15. Per 10,000 emails a month · checked 25 Nov 2026. From $15 a month for 10,000 emails (Basic) to $775 for 1,500,000 emails (Basic); above that, Custom pricing. List prices before tax (postmarkapp.com, 25 Nov 2026).
- [Mailjet pricing](https://nightmail.dev/pricing/mailjet.md): Nightmail $0.60. Mailjet $9. Per 8,000 emails a month · checked 25 Nov 2026. From $9 a month for 8,000 emails (Starter) to $499 for 500,000 emails (Premium); above that, Custom, by quote. List prices before tax (mailjet.com, 25 Nov 2026).
- [Brevo pricing](https://nightmail.dev/pricing/brevo.md): Nightmail $7. Brevo $46. Per 10,000 contacts, 40,000 emails a month · checked 25 Nov 2026. From $9 a month for 500 contacts (Starter) to $499 for 2,000,000 contacts (Professional), the largest size read here. List prices before tax (brevo.com, 25 Nov 2026).
- [Mandrill pricing](https://nightmail.dev/pricing/mandrill.md): Nightmail $4. Mandrill $20. Per 25,000 emails a month · checked 25 Nov 2026. From $20 a month for 25,000 emails (1 block) to $1,400 for 2,500,000 emails (100 blocks), the largest size read here. List prices before tax (mailchimp.com, 25 Nov 2026).
- [SendGrid alternatives](https://nightmail.dev/alternatives/sendgrid.md): Nightmail $19. 7 others from $30. SendGrid and six alternatives, per 100,000 emails a month · checked 25–26 Nov 2026: SendGrid $34.95, Mailtrap $30, MailChannels $30, Resend $35, Bird $40, UniOne $40, AhaSend $47.50.
- [Resend alternatives](https://nightmail.dev/alternatives/resend.md): Nightmail $19. 7 others from $30. Resend and six alternatives, per 100,000 emails a month · checked 25–26 Nov 2026: Resend $35, Mailtrap $30, MailChannels $30, SendGrid $34.95, Bird $40, UniOne $40, AhaSend $47.50.
- [Mailgun alternatives](https://nightmail.dev/alternatives/mailgun.md): Nightmail $19. 7 others from $30. Mailgun and six alternatives, per 100,000 emails a month · checked 25–26 Nov 2026: Mailgun $75, Mailtrap $30, MailChannels $30, SendGrid $34.95, Resend $35, Bird $40, UniOne $40.
- [Postmark alternatives](https://nightmail.dev/alternatives/postmark.md): Nightmail $24. 7 others from $56.95. Postmark and six alternatives, per 125,000 emails a month · checked 25–26 Nov 2026: Postmark $115, SendGrid $56.95, Resend $57.50, UniOne $58.75, MailChannels $60, SMTP2GO $96.25, Mandrill $100.
- [Mailchimp alternatives](https://nightmail.dev/alternatives/mailchimp.md): Nightmail $19. 7 others from $82. Mailchimp and six alternatives, per 25,000 contacts, 100,000 emails a month · checked 25 Nov 2026: Mailchimp $270, Brevo $82, EmailOctopus $94.50, Ghost(Pro) $169, MailerLite $179, beehiiv $199, Loops $199.
- [Mandrill alternatives](https://nightmail.dev/alternatives/mandrill.md): Nightmail $19. 7 others from $30. Mandrill and six alternatives, per 100,000 emails a month · checked 25–26 Nov 2026: Mandrill $80, Mailtrap $30, MailChannels $30, SendGrid $34.95, Resend $35, Bird $40, UniOne $40.
- [Email for AI agents](https://nightmail.dev/email-for-ai-agents.md): Nightmail $0. 9 others from $19. Nine agent-inbox services, 50 inboxes, 100 in and 50 out each a month · checked 25 Nov 2026: Dead Simple Email $19, Lumbox $29, Nylas $49, Robotomail $79, Mails.ai $99, AgentMail $100, Inkbox $130, Agent Identity $149, Postfleet $200.
- [Email API prices](https://nightmail.dev/cheapest-email-api.md): Nightmail $19. 10 others from $30. Ten of 15 email APIs compared, per 100,000 emails a month · checked 25–26 Nov 2026. These are the 15 email-sending APIs Nightmail has compared itself with, not every email service.
- [Free email API plans](https://nightmail.dev/free-email-api.md): 5,000 emails free. Every month. Nightmail, beside 15 email APIs’ free allowances · checked 25–26 Nov 2026. Listed: the 26 of 34 email services Nightmail has compared itself with whose free allowance is smaller than its own, or is a trial or a one-off (15 email APIs, 5 newsletter services, 6 agent-inbox services); this is not every email service.

## Comparisons

- [Nightmail vs AgentMail](https://nightmail.dev/compare/agentmail.md): AgentMail costs at least 20 times as much as Nightmail. At 100 agent inboxes, each 100 in and 50 out a month: AgentMail $200 (Startup), Nightmail $0; AgentMail’s prices checked 25 Nov 2026.
- [Nightmail vs Nylas](https://nightmail.dev/compare/nylas.md): Nylas costs over 17 times as much as Nightmail. At 100 agent inboxes, each 100 in and 50 out a month: Nylas $69 (Pro + 50 accounts), Nightmail $0; Nylas’s prices checked 25 Nov 2026.
- [Nightmail vs Robotomail](https://nightmail.dev/compare/robotomail.md): Robotomail costs at least 20 times as much as Nightmail. At 50 agent inboxes, each 100 in and 50 out a month: Robotomail $79 (Growth), Nightmail $0; Robotomail’s prices checked 25 Nov 2026.
- [Nightmail vs Postfleet](https://nightmail.dev/compare/postfleet.md): Postfleet costs at least 20 times as much as Nightmail. At 50 agent inboxes, each 100 in and 50 out a month: Postfleet $200 (Scale), Nightmail $0; Postfleet’s prices checked 25 Nov 2026.
- [Nightmail vs Lumbox](https://nightmail.dev/compare/lumbox.md): Lumbox costs at least 20 times as much as Nightmail. At 50 agent inboxes, each 100 in and 50 out a month: Lumbox $29 (Pro), Nightmail $0; Lumbox’s prices checked 25 Nov 2026.
- [Nightmail vs Mails.ai](https://nightmail.dev/compare/mails-ai.md): Mails.ai costs over 3 times as much as Nightmail. At 100 agent inboxes, each 100 in and 50 out a month: Mails.ai $99 (Scale), Nightmail $0; Mails.ai’s prices checked 25 Nov 2026.
- [Nightmail vs Dead Simple Email](https://nightmail.dev/compare/dead-simple-email.md): Dead Simple Email costs over 9 times as much as Nightmail. At 100 agent inboxes, each 100 in and 50 out a month: Dead Simple Email $29 (Pro), Nightmail $0; Dead Simple Email’s prices checked 25 Nov 2026.
- [Nightmail vs Agent Identity](https://nightmail.dev/compare/agent-identity.md): Nightmail costs less than Agent Identity. At 25 agent inboxes, each 100 in and 50 out a month: Agent Identity $149 (Team), Nightmail $0; Agent Identity’s prices checked 25 Nov 2026.
- [Nightmail vs Inkbox](https://nightmail.dev/compare/inkbox.md): Nightmail costs less than Inkbox. At 25 agent inboxes, each 100 in and 50 out a month: Inkbox $130 (Developer + 100 identities), Nightmail $0; Inkbox’s prices checked 25 Nov 2026.
- [Nightmail vs Resend](https://nightmail.dev/compare/resend.md): Nightmail costs less than Resend. At 100,000 emails a month: Resend $35 (Pro), Nightmail $19; Resend’s prices checked 25 Nov 2026.
- [Nightmail vs SendGrid](https://nightmail.dev/compare/sendgrid.md): Nightmail costs less than SendGrid. At 100,000 emails a month: SendGrid $34.95 (Essentials), Nightmail $19; SendGrid’s prices checked 25 Nov 2026.
- [Nightmail vs Postmark](https://nightmail.dev/compare/postmark.md): Postmark costs over 2 times as much as Nightmail. At 125,000 emails a month: Postmark $115 (Basic), Nightmail $24; Postmark’s prices checked 25 Nov 2026.
- [Nightmail vs Mailgun](https://nightmail.dev/compare/mailgun.md): Mailgun costs over 2 times as much as Nightmail. At 100,000 emails a month: Mailgun $75 (Foundation), Nightmail $19; Mailgun’s prices checked 25 Nov 2026.
- [Nightmail vs Mailjet](https://nightmail.dev/compare/mailjet.md): Mailjet costs over 4 times as much as Nightmail. At 100,000 emails a month: Mailjet $112 (Premium), Nightmail $19; Mailjet’s prices checked 25 Nov 2026.
- [Nightmail vs Mandrill](https://nightmail.dev/compare/mandrill.md): Mandrill costs over 2 times as much as Nightmail. At 100,000 emails a month: Mandrill $80 (4 blocks), Nightmail $19; Mandrill’s prices checked 25 Nov 2026.
- [Nightmail vs Bird](https://nightmail.dev/compare/bird.md): Nightmail costs less than Bird. At 100,000 emails a month: Bird $40 (Email Startup), Nightmail $19; Bird’s prices checked 26 Nov 2026.
- [Nightmail vs MailerSend](https://nightmail.dev/compare/mailersend.md): MailerSend costs over 3 times as much as Nightmail. At 100,000 emails a month: MailerSend $68 (Starter), Nightmail $19; MailerSend’s prices checked 25 Nov 2026.
- [Nightmail vs Mailtrap](https://nightmail.dev/compare/mailtrap.md): Nightmail costs less than Mailtrap. At 100,000 emails a month: Mailtrap $30 (Basic), Nightmail $19; Mailtrap’s prices checked 25 Nov 2026.
- [Nightmail vs SMTP2GO](https://nightmail.dev/compare/smtp2go.md): Nightmail costs less than SMTP2GO. At 100,000 emails a month: SMTP2GO $75 (Professional), Nightmail $19; SMTP2GO’s prices checked 26 Nov 2026.
- [Nightmail vs AhaSend](https://nightmail.dev/compare/ahasend.md): AhaSend costs over 2 times as much as Nightmail. At 100,000 emails a month: AhaSend $47.50 (Pro), Nightmail $19; AhaSend’s prices checked 26 Nov 2026.
- [Nightmail vs CloudMailin](https://nightmail.dev/compare/cloudmailin.md): Nightmail costs less than CloudMailin. At 100,000 emails received a month: CloudMailin $200 (Corporate), Nightmail $16; CloudMailin’s prices checked 25 Nov 2026.
- [Nightmail vs SocketLabs](https://nightmail.dev/compare/socketlabs.md): SocketLabs costs over 3 times as much as Nightmail. At 100,000 emails a month: SocketLabs $89.95 (Pro), Nightmail $19; SocketLabs’s prices checked 25 Nov 2026.
- [Nightmail vs MailPace](https://nightmail.dev/compare/mailpace.md): MailPace costs over 5 times as much as Nightmail. At 100,000 emails a month: MailPace $100 (Scaling), Nightmail $19; MailPace’s prices checked 25 Nov 2026.
- [Nightmail vs UniOne](https://nightmail.dev/compare/unione.md): UniOne costs over 2 times as much as Nightmail. At 100,000 emails a month: UniOne $40 (Standard), Nightmail $19; UniOne’s prices checked 25 Nov 2026.
- [Nightmail vs MailChannels](https://nightmail.dev/compare/mailchannels.md): Nightmail costs less than MailChannels. At 100,000 emails a month: MailChannels $30 (Pay as You Grow), Nightmail $19; MailChannels’s prices checked 25 Nov 2026.
- [Nightmail vs Mailchimp](https://nightmail.dev/compare/mailchimp.md): Mailchimp costs over 9 times as much as Nightmail. At 25,000 contacts emailed 4 times a month: Mailchimp $270 (Essentials), Nightmail $19; Mailchimp’s prices checked 25 Nov 2026.
- [Nightmail vs beehiiv](https://nightmail.dev/compare/beehiiv.md): beehiiv costs over 5 times as much as Nightmail. At 10,000 contacts emailed 4 times a month: beehiiv $139 (Lite), Nightmail $7; beehiiv’s prices checked 25 Nov 2026.
- [Nightmail vs MailerLite](https://nightmail.dev/compare/mailerlite.md): MailerLite costs over 5 times as much as Nightmail. At 10,000 contacts emailed 4 times a month: MailerLite $89 (Comfort), Nightmail $7; MailerLite’s prices checked 25 Nov 2026.
- [Nightmail vs Buttondown](https://nightmail.dev/compare/buttondown.md): Buttondown costs over 6 times as much as Nightmail. At 10,000 contacts emailed 4 times a month: Buttondown $79 (Paid), Nightmail $7; Buttondown’s prices checked 25 Nov 2026.
- [Nightmail vs EmailOctopus](https://nightmail.dev/compare/emailoctopus.md): EmailOctopus costs over 3 times as much as Nightmail. At 10,000 contacts emailed 4 times a month: EmailOctopus $44.50 (Pro), Nightmail $7; EmailOctopus’s prices checked 25 Nov 2026.
- [Nightmail vs Ghost(Pro)](https://nightmail.dev/compare/ghost.md): Ghost(Pro) costs over 4 times as much as Nightmail. At 10,000 contacts emailed 4 times a month: Ghost(Pro) $105 (Publisher), Nightmail $7; Ghost(Pro)’s prices checked 25 Nov 2026.
- [Nightmail vs AWeber](https://nightmail.dev/compare/aweber.md): AWeber costs over 7 times as much as Nightmail. At 10,000 contacts emailed 4 times a month: AWeber $100 (Lite), Nightmail $7; AWeber’s prices checked 25 Nov 2026.
- [Nightmail vs Loops](https://nightmail.dev/compare/loops.md): Loops costs over 4 times as much as Nightmail. At 10,000 contacts emailed 4 times a month: Loops $99 (Growth), Nightmail $7; Loops’s prices checked 25 Nov 2026.
- [Nightmail vs Brevo](https://nightmail.dev/compare/brevo.md): Brevo costs over 4 times as much as Nightmail. At 10,000 contacts emailed 4 times a month: Brevo $46 (Starter), Nightmail $7; Brevo’s prices checked 25 Nov 2026.

## Quickstart

1. **Add and verify your domain.** In the dashboard, open Domains and add it, or call POST /v1/domains with {"name":"acme.com"}. Publish the DNS records it returns at your DNS provider. Sending works once GET /v1/domains/{id} reports sending: "verified", usually within minutes of the records resolving. A domain whose records are still unproven after 72 hours is released.
2. **Create an API key.** In the dashboard, open API keys in the sidebar and choose Create key. A Send only key restricted to your domain is enough to send; it can’t read logs, so add Read permission if your code should look up outcomes. Store it as NIGHTMAIL_API_KEY on your server and never ship it to a browser.
3. **Send.** 202 means queued, not delivered. Follow the outcome in the dashboard’s Logs, or with GET /v1/emails/{id} and a key that has Read permission (a Send only key gets 403). Leave out region: the sender domain decides it. To test without reaching a real inbox, send to success@simulator.amazonses.com (or bounce@, complaint@, ooto@ and suppressionlist@ the same domain). Simulator sends use your daily sending limit like any other send, but never count towards your sender score.

   ```sh
   curl --request POST \
     --url 'https://nightmail.dev/v1/emails/send' \
     --header "Authorization: Bearer $NIGHTMAIL_API_KEY" \
     --header 'Content-Type: application/json' \
     --header "Idempotency-Key: $(uuidgen)" \
     --data '{"from":"hello@acme.com","to":"you@acme.com","subject":"Hello from Nightmail","text":"It works."}'
   ```
4. **Receive (optional).** Publish the receiving MX record from the domain page. Hosted Nightmail receives on a free subdomain such as reply.<your domain>, so the domain’s existing mailboxes keep working; it uses the domain itself only when its MX already points to Nightmail, or when you choose it. Create an inbox with POST /v1/inboxes and read mail with GET /v1/inboxes/{id}/messages (or subscribe to message.received with POST /v1/inbound/webhooks).
5. **Reply.** POST /v1/inbound/threads/{threadId}/reply answers the newest message from its receiving address and sets In-Reply-To and References.

## Give a coding agent its own key

A coding agent gets its own API key without one made by hand, in one of two ways. The prompt is the quicker: the person copies it where they already are and the agent connects in seconds, while a device code waits for the person to open a link the agent shows somewhere else. With the prompt: when an owner or admin copies the agent prompt in the dashboard (onboarding, Docs or Connect an agent), the copy carries a one-time setup token (nm_setup_…) that works for 15 minutes, and the agent exchanges it with POST /v1/agent/setup. Copying again replaces an unused token. An expired or replaced token answers 410 with a device code in error.details[0] for the person who copied it to approve, and their dashboard shows the agent waiting. Without it (RFC 8628 device flow): POST /v1/agent/device returns a device_code, a user_code and verification_uri_complete; show the person that link on its own line (nextStep says so) and they open it (Nightmail's /connect page), signs in, checks the code, chooses the workspace and approves; meanwhile the agent polls POST /v1/agent/device/token every interval seconds. 400 AUTHORIZATION_PENDING means keep waiting, SLOW_DOWN wait five seconds longer from now on, ACCESS_DENIED stop, and EXPIRED_TOKEN that nobody approved in time: the first carries a new code in error.details[0] (once), after that start again. Each pending answer repeats the link. Either way the agent gets one key, named after its client_name ("My agent, set up <date>"): read, send and manage on every domain, so it sends email and manages domains, inboxes, receiving, webhooks, audience and campaigns. It can't create API keys, agent tokens, inbox connection keys, inbox keys or mail-client (IMAP/SMTP) passwords, and never reaches members or billing: it works with inboxes through its own key. It is shown once: keep it as NIGHTMAIL_API_KEY in the project's environment, never in code. Asked again, the setup token or device code answers 409 naming the key it gave (error.details), never a second key. A revoked key answers 401 KEY_REVOKED: run setup again. The response also has an MCP config that reads it from there. A person revokes it under API keys, and Activity names who set it up.

```sh
# With the setup token in the prompt:
curl -sS -X POST https://nightmail.dev/v1/agent/setup -H 'Content-Type: application/json' \
  -d '{"token":"nm_setup_…","client_name":"My agent"}'

# Without one: start the device flow and show the person verification_uri_complete and user_code ...
curl -sS -X POST https://nightmail.dev/v1/agent/device -H 'Content-Type: application/json' -d '{"client_name":"My agent"}'
# ... then poll every interval seconds until it returns the key.
curl -sS -X POST https://nightmail.dev/v1/agent/device/token -H 'Content-Type: application/json' \
  -d '{"device_code":"nm_device_…"}'
```

## Send from the built-in domain

Every Hosted workspace starts with a domain of its own, such as acme-k7.nightmail.email: Domains lists it as Built-in, and connection.builtinDomain in GET /v1/me and limits in GET /v1/domains/{id} describe it. It needs no DNS and sends at once. For now, built-in domains send only to your workspace members’ own sign-in addresses, up to 10 a day (3 a minute), and only plain transactional mail: no Reply-To elsewhere, custom headers, attachments, stored templates, scheduling, marketing or campaigns. Add your own domain to email anyone and to use them. (limits.scope says who yours sends to.) A send to anyone else is refused with 422 BUILTIN_DOMAIN_RECIPIENT, naming those recipients in error.details[0].notMembers, with sendsTo ("workspaceMembers") and nextStep (createDomain, POST /v1/domains); it is not retryable. A send that uses any of the rest is refused once, with 422 BUILTIN_DOMAIN_UNSUPPORTED naming every field it used in error.details[0].unsupported (for example ["replyTo","headers","attachments"]); past a cap it is 429 BUILTIN_DOMAIN_LIMIT with resetAt. It receives at every address: mail to an address without an inbox or route of its own goes to its default inbox, hello@ the domain, and replies from there (POST /v1/inbound/threads/{threadId}/reply) follow the same rules and caps: while it sends to members only, a reply to anyone outside the workspace gets the same 422 BUILTIN_DOMAIN_RECIPIENT, and answering them needs a domain of your own. Where connection.builtinDomain.repliesToSenders is true, a reply may go once to the sender of the message it answers, alone, when that sender passed authentication and the message isn't automated, within a daily count for the workspace; never to another built-in domain or to one of Nightmail’s own addresses except support, so an agent can answer what Nightmail support sent it; otherwise error.details[0].reply says which condition it didn't meet. Once a domain of the workspace’s own verifies, the built-in domain stops sending and keeps receiving: a send from it then gets 409 OWN_DOMAIN_VERIFIED with the same address at your own domain in error.details[0].suggestedFrom (every verified domain in verifiedDomains), so switch From to your own domain as soon as it verifies. Nightmail may turn one off for abuse.

## Verify webhook signatures

Every webhook delivery (email events and inbound webhooks alike) carries Webhook-Id, Webhook-Timestamp (Unix seconds) and Webhook-Signature headers in the Standard Webhooks format. Compute HMAC-SHA256 over "{Webhook-Id}.{Webhook-Timestamp}.{raw body}" with the base64-decoded part of the signing secret after whsec_, and compare it in constant time to the value after v1, in Webhook-Signature. Reject timestamps more than five minutes old, and use Webhook-Id to skip a delivery you already handled. Standard Webhooks libraries (such as the standardwebhooks npm package) verify it too. Failed deliveries (408, 429, 5xx or network error) are tried up to 10 times with exponential backoff (15 s, 1 min, 4 min, 16 min, 64 min, ~4.3 h, then 12 h between remaining attempts, honoring Retry-After). The secret is shown once when you create a webhook; reveal or rotate it on the webhook’s page, or with revealWebhookSecret (from an API key you made) and rotateWebhookSecret. MCP approvals can rotate it but not read it back; temporary agent tokens can do neither. Every reveal and rotation is recorded.

```js
import { createHmac, timingSafeEqual } from 'node:crypto'

// secret: the webhook's signing secret (whsec_…). body: the raw request body, before JSON.parse.
export function verifyNightmailWebhook(secret, headers, body) {
  const id = headers['webhook-id'], timestamp = headers['webhook-timestamp']
  if (!id || !timestamp || Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false
  const key = Buffer.from(secret.slice('whsec_'.length), 'base64')
  const expected = createHmac('sha256', key).update(`${id}.${timestamp}.${body}`).digest()
  return String(headers['webhook-signature'] ?? '').split(' ').some(part => {
    const [version, signature = ''] = part.split(',')
    const given = Buffer.from(signature, 'base64')
    return version === 'v1' && given.length === expected.length && timingSafeEqual(given, expected)
  })
}
```

## Start here (core operations)

Most integrations only need these 9 operations to verify a domain, send mail and receive replies:

- Create domain (POST /v1/domains): /docs/operations/createDomain.md — Add a domain and get its DNS records
- Get domain (GET /v1/domains/{id}): /docs/operations/getDomain.md — Check domain verification status
- Verify domain (POST /v1/domains/{id}/verify): /docs/operations/verifyDomain.md — Trigger a fresh DNS verification check
- Send email (POST /v1/emails/send): /docs/operations/sendEmail.md — Queue an email (202 = queued)
- Get email (GET /v1/emails/{id}): /docs/operations/getEmail.md — Check delivery status of a sent email
- Enable inbound domain (POST /v1/inbound/domains/{id}/enable): /docs/operations/enableInboundDomain.md — Turn on receiving for a verified domain
- Create inbox (POST /v1/inboxes): /docs/operations/createInbox.md — Create a receiving inbox/address
- List inbox messages (GET /v1/inboxes/{id}/messages): /docs/operations/listInboxMessages.md — Read messages received by an inbox
- Get inbox message (GET /v1/inboxes/{id}/messages/{messageId}): /docs/operations/getInboxMessage.md — Read one received message and its extracted codes/links

## Canonical documentation

- Markdown API reference index: /docs.md
- Interactive API reference: /docs
- OpenAPI 3.1 definition: /openapi.json
- TypeScript SDK: https://www.npmjs.com/package/@nightmail/sdk
- MCP endpoint: /mcp

## Markdown API reference by tag

### Core API

- Emails: /docs/tags/emails.md
- Domains: /docs/tags/domains.md
- Agent inboxes: /docs/tags/agent-inboxes.md
- Inbound domains: /docs/tags/inbound-domains.md
- Inbound threads: /docs/tags/inbound-threads.md
- Inbound events: /docs/tags/inbound-events.md
- Inbound webhooks: /docs/tags/inbound-webhooks.md
- Webhooks: /docs/tags/webhooks.md
- Attachments: /docs/tags/attachments.md
- Metrics: /docs/tags/metrics.md
- ApiKeys: /docs/tags/api-keys.md
- Settings: /docs/tags/settings.md

### Campaigns, audience & automation

- Campaigns: /docs/tags/campaigns.md
- Templates: /docs/tags/templates.md
- Audience: /docs/tags/audience.md
- Consent: /docs/tags/consent.md
- Newsletters: /docs/tags/newsletters.md
- Routing: /docs/tags/routing.md
- Rules: /docs/tags/rules.md
- Endpoints: /docs/tags/endpoints.md
- Billing: /docs/tags/billing.md
- Feedback: /docs/tags/feedback.md

### Dashboard, self-hosted, webhooks & deprecated

- Inbound addresses: /docs/tags/inbound-addresses.md
- Regions: /docs/tags/regions.md
- Workspaces: /docs/tags/workspaces.md
- Auth: /docs/tags/auth.md
- Events: /docs/tags/events.md

## Focused operation documentation

- Check email: /docs/operations/checkEmail.md
- Send email: /docs/operations/sendEmail.md
- Send email batch: /docs/operations/sendEmailBatch.md
- Preview email: /docs/operations/previewEmail.md
- List emails: /docs/operations/listEmails.md
- Get email: /docs/operations/getEmail.md
- Get email detail: /docs/operations/getEmailDetail.md
- Get email content: /docs/operations/getEmailContent.md
- List email events: /docs/operations/listEmailEvents.md
- Cancel email: /docs/operations/cancelEmail.md
- Reschedule email: /docs/operations/rescheduleEmail.md
- List logs: /docs/operations/listLogs.md
- List domains: /docs/operations/listDomains.md
- Create domain: /docs/operations/createDomain.md
- Configure domain mail from: /docs/operations/configureDomainMailFrom.md
- Remove domain mail from: /docs/operations/removeDomainMailFrom.md
- Choose receiving host: /docs/operations/chooseReceivingHost.md
- Complete domain dns setup: /docs/operations/completeDomainDnsSetup.md
- Get domain: /docs/operations/getDomain.md
- Delete domain: /docs/operations/deleteDomain.md
- Verify domain: /docs/operations/verifyDomain.md
- Create inbox connection: /docs/operations/createInboxConnection.md
- List inbox folders: /docs/operations/listInboxFolders.md
- Create inbox folder: /docs/operations/createInboxFolder.md
- Update inbox folder: /docs/operations/updateInboxFolder.md
- Delete inbox folder: /docs/operations/deleteInboxFolder.md
- Get inbox message: /docs/operations/getInboxMessage.md
- Update inbox message: /docs/operations/updateInboxMessage.md
- Delete inbox message: /docs/operations/deleteInboxMessage.md
- Move inbox message: /docs/operations/moveInboxMessage.md
- Copy inbox message: /docs/operations/copyInboxMessage.md
- Expunge inbox folder: /docs/operations/expungeInboxFolder.md
- Get inbox changes: /docs/operations/getInboxChanges.md
- List inbox app passwords [deprecated]: /docs/operations/listInboxAppPasswords.md
- Create inbox app password: /docs/operations/createInboxAppPassword.md
- List app passwords: /docs/operations/listAppPasswords.md
- Revoke inbox app password: /docs/operations/revokeInboxAppPassword.md
- List inboxes: /docs/operations/listInboxes.md
- Create inbox: /docs/operations/createInbox.md
- Get inbox: /docs/operations/getInbox.md
- Update inbox: /docs/operations/updateInbox.md
- Delete inbox: /docs/operations/deleteInbox.md
- Simulate inbox message: /docs/operations/simulateInboxMessage.md
- List inbox messages: /docs/operations/listInboxMessages.md
- Get inbox attachment: /docs/operations/getInboxAttachment.md
- Get inbound scan policy: /docs/operations/getInboundScanPolicy.md
- Update inbound scan policy: /docs/operations/updateInboundScanPolicy.md
- List inbound domains: /docs/operations/listInboundDomains.md
- Get inbound domain: /docs/operations/getInboundDomain.md
- Update inbound domain: /docs/operations/updateInboundDomain.md
- Check inbound domain: /docs/operations/checkInboundDomain.md
- Enable inbound domain: /docs/operations/enableInboundDomain.md
- Disable inbound domain: /docs/operations/disableInboundDomain.md
- List receiving hosts: /docs/operations/listReceivingHosts.md
- Add receiving host: /docs/operations/addReceivingHost.md
- Update receiving host: /docs/operations/updateReceivingHost.md
- Remove receiving host: /docs/operations/removeReceivingHost.md
- List inbound subdomains: /docs/operations/listInboundSubdomains.md
- Create inbound subdomain: /docs/operations/createInboundSubdomain.md
- Get inbound subdomain: /docs/operations/getInboundSubdomain.md
- Update inbound subdomain: /docs/operations/updateInboundSubdomain.md
- Remove inbound subdomain: /docs/operations/removeInboundSubdomain.md
- List inbound threads: /docs/operations/listInboundThreads.md
- Create inbound thread: /docs/operations/createInboundThread.md
- Get inbound thread: /docs/operations/getInboundThread.md
- Update inbound thread: /docs/operations/updateInboundThread.md
- List inbound messages: /docs/operations/listInboundMessages.md
- Get inbound message: /docs/operations/getInboundMessage.md
- Get inbound attachment: /docs/operations/getInboundAttachment.md
- Download inbound attachment: /docs/operations/downloadInboundAttachment.md
- Reply to inbound thread: /docs/operations/replyToInboundThread.md
- List inbound events: /docs/operations/listInboundEvents.md
- List inbound webhooks: /docs/operations/listInboundWebhooks.md
- Create inbound webhook: /docs/operations/createInboundWebhook.md
- Get inbound webhook: /docs/operations/getInboundWebhook.md
- Update inbound webhook: /docs/operations/updateInboundWebhook.md
- Delete inbound webhook: /docs/operations/deleteInboundWebhook.md
- Test inbound webhook: /docs/operations/testInboundWebhook.md
- Redeliver inbound message: /docs/operations/redeliverInboundMessage.md
- Rotate inbound webhook secret: /docs/operations/rotateInboundWebhookSecret.md
- Retry inbound webhook delivery: /docs/operations/retryInboundWebhookDelivery.md
- List inbound webhook deliveries: /docs/operations/listInboundWebhookDeliveries.md
- List webhooks: /docs/operations/listWebhooks.md
- Create webhook: /docs/operations/createWebhook.md
- Get webhook: /docs/operations/getWebhook.md
- Update webhook: /docs/operations/updateWebhook.md
- Delete webhook: /docs/operations/deleteWebhook.md
- Reveal webhook secret: /docs/operations/revealWebhookSecret.md
- Rotate webhook secret: /docs/operations/rotateWebhookSecret.md
- Test webhook: /docs/operations/testWebhook.md
- List webhook deliveries: /docs/operations/listWebhookDeliveries.md
- Get webhook delivery: /docs/operations/getWebhookDelivery.md
- Retry webhook delivery: /docs/operations/retryWebhookDelivery.md
- Upload attachment: /docs/operations/uploadAttachment.md
- Get attachment: /docs/operations/getAttachment.md
- Delete attachment: /docs/operations/deleteAttachment.md
- Get attachment content: /docs/operations/getAttachmentContent.md
- Get metrics: /docs/operations/getMetrics.md
- Get sender score: /docs/operations/getSenderScore.md
- Get usage: /docs/operations/getUsage.md
- Get public stats: /docs/operations/getPublicStats.md
- List api keys: /docs/operations/listApiKeys.md
- Create api key: /docs/operations/createApiKey.md
- List api key changes: /docs/operations/listApiKeyChanges.md
- Revoke api key: /docs/operations/revokeApiKey.md
- Update api key: /docs/operations/updateApiKey.md
- Get workspace settings: /docs/operations/getWorkspaceSettings.md
- Update workspace settings: /docs/operations/updateWorkspaceSettings.md
- Get ses settings: /docs/operations/getSesSettings.md
- Get overview setup: /docs/operations/getOverviewSetup.md
- List campaigns: /docs/operations/listCampaigns.md
- Create campaign: /docs/operations/createCampaign.md
- Get campaign: /docs/operations/getCampaign.md
- Update campaign: /docs/operations/updateCampaign.md
- Delete campaign: /docs/operations/deleteCampaign.md
- Get campaign stats: /docs/operations/getCampaignStats.md
- Get campaign content guide: /docs/operations/getCampaignContentGuide.md
- Preview campaign: /docs/operations/previewCampaign.md
- Preview campaign audience: /docs/operations/previewCampaignAudience.md
- Render campaign preview image: /docs/operations/renderCampaignPreviewImage.md
- Get campaign state: /docs/operations/getCampaignState.md
- Set campaign archived: /docs/operations/setCampaignArchived.md
- Test campaign: /docs/operations/testCampaign.md
- Send campaign: /docs/operations/sendCampaign.md
- Schedule campaign: /docs/operations/scheduleCampaign.md
- Cancel campaign: /docs/operations/cancelCampaign.md
- Pause campaign: /docs/operations/pauseCampaign.md
- Resume campaign: /docs/operations/resumeCampaign.md
- Set campaign pacing: /docs/operations/setCampaignPacing.md
- Unschedule campaign: /docs/operations/unscheduleCampaign.md
- Reschedule campaign: /docs/operations/rescheduleCampaign.md
- List campaign templates: /docs/operations/listCampaignTemplates.md
- Create campaign template: /docs/operations/createCampaignTemplate.md
- Get campaign template: /docs/operations/getCampaignTemplate.md
- Update campaign template: /docs/operations/updateCampaignTemplate.md
- Delete campaign template: /docs/operations/deleteCampaignTemplate.md
- Publish campaign template: /docs/operations/publishCampaignTemplate.md
- Preview campaign template: /docs/operations/previewCampaignTemplate.md
- Render campaign template preview image: /docs/operations/renderCampaignTemplatePreviewImage.md
- Set campaign template archived: /docs/operations/setCampaignTemplateArchived.md
- Upload template asset: /docs/operations/uploadTemplateAsset.md
- Import template image: /docs/operations/importTemplateImage.md
- Get template asset: /docs/operations/getTemplateAsset.md
- Delete template asset: /docs/operations/deleteTemplateAsset.md
- Get template asset content: /docs/operations/getTemplateAssetContent.md
- List contacts: /docs/operations/listContacts.md
- Create contact: /docs/operations/createContact.md
- Get contact: /docs/operations/getContact.md
- Update contact: /docs/operations/updateContact.md
- Delete contact: /docs/operations/deleteContact.md
- List contact lists: /docs/operations/listContactLists.md
- Create contact list: /docs/operations/createContactList.md
- Get contact list: /docs/operations/getContactList.md
- Update contact list: /docs/operations/updateContactList.md
- Delete contact list: /docs/operations/deleteContactList.md
- List list members: /docs/operations/listListMembers.md
- Add list members: /docs/operations/addListMembers.md
- Remove list member: /docs/operations/removeListMember.md
- List segments: /docs/operations/listSegments.md
- Create segment: /docs/operations/createSegment.md
- Get segment: /docs/operations/getSegment.md
- Update segment: /docs/operations/updateSegment.md
- Delete segment: /docs/operations/deleteSegment.md
- Preview segment: /docs/operations/previewSegment.md
- List contact imports: /docs/operations/listContactImports.md
- Preview contact import: /docs/operations/previewContactImport.md
- Get contact import: /docs/operations/getContactImport.md
- Commit contact import: /docs/operations/commitContactImport.md
- List topics: /docs/operations/listTopics.md
- Create topic: /docs/operations/createTopic.md
- Update topic: /docs/operations/updateTopic.md
- Query audience: /docs/operations/queryAudience.md
- Plan audience mutation: /docs/operations/planAudienceMutation.md
- Apply audience plan: /docs/operations/applyAudiencePlan.md
- List contact consent events: /docs/operations/listContactConsentEvents.md
- Update contact consent: /docs/operations/updateContactConsent.md
- Unsubscribe by link: /docs/operations/unsubscribeByLink.md
- Unsubscribe one click: /docs/operations/unsubscribeOneClick.md
- List newsletters: /docs/operations/listNewsletters.md
- Create newsletter: /docs/operations/createNewsletter.md
- Get newsletter: /docs/operations/getNewsletter.md
- Update newsletter: /docs/operations/updateNewsletter.md
- Delete newsletter: /docs/operations/deleteNewsletter.md
- Get routing: /docs/operations/getRouting.md
- Apply routing: /docs/operations/applyRouting.md
- List routes: /docs/operations/listRoutes.md
- Create route: /docs/operations/createRoute.md
- Get route: /docs/operations/getRoute.md
- Update route: /docs/operations/updateRoute.md
- Delete route: /docs/operations/deleteRoute.md
- Get routing audit: /docs/operations/getRoutingAudit.md
- List routing versions: /docs/operations/listRoutingVersions.md
- Get routing version: /docs/operations/getRoutingVersion.md
- Restore routing version: /docs/operations/restoreRoutingVersion.md
- Test routing: /docs/operations/testRouting.md
- List rule versions: /docs/operations/listRuleVersions.md
- Restore rule version: /docs/operations/restoreRuleVersion.md
- Set decision opt ins: /docs/operations/setDecisionOptIns.md
- Get rule version: /docs/operations/getRuleVersion.md
- Check rule: /docs/operations/checkRule.md
- Get rule typings: /docs/operations/getRuleTypings.md
- List rule templates: /docs/operations/listRuleTemplates.md
- List rule recipes: /docs/operations/listRuleRecipes.md
- Create rule from recipe: /docs/operations/createRuleFromRecipe.md
- Update rule from recipe: /docs/operations/updateRuleFromRecipe.md
- Get rule: /docs/operations/getRule.md
- Save rule: /docs/operations/saveRule.md
- Update rule: /docs/operations/updateRule.md
- Delete rule: /docs/operations/deleteRule.md
- Attach rules: /docs/operations/attachRules.md
- Get rules: /docs/operations/getRules.md
- Apply rules: /docs/operations/applyRules.md
- Test rules: /docs/operations/testRules.md
- List endpoints: /docs/operations/listEndpoints.md
- Create endpoint: /docs/operations/createEndpoint.md
- Get endpoint: /docs/operations/getEndpoint.md
- Update endpoint: /docs/operations/updateEndpoint.md
- Delete endpoint: /docs/operations/deleteEndpoint.md
- Send endpoint verification: /docs/operations/sendEndpointVerification.md
- Test endpoint: /docs/operations/testEndpoint.md
- List inbound endpoints: /docs/operations/listInboundEndpoints.md
- Get billing: /docs/operations/getBilling.md
- Get billing usage: /docs/operations/getBillingUsage.md
- List billing ledger: /docs/operations/listBillingLedger.md
- List billing payments: /docs/operations/listBillingPayments.md
- Get billing payment: /docs/operations/getBillingPayment.md
- Create billing top up link: /docs/operations/createBillingTopUpLink.md
- Send feedback: /docs/operations/sendFeedback.md
- Release retired address: /docs/operations/releaseRetiredAddress.md
- List inbound addresses [deprecated]: /docs/operations/listInboundAddresses.md
- Create inbound address [deprecated]: /docs/operations/createInboundAddress.md
- Get inbound address [deprecated]: /docs/operations/getInboundAddress.md
- Update inbound address [deprecated]: /docs/operations/updateInboundAddress.md
- Delete inbound address [deprecated]: /docs/operations/deleteInboundAddress.md
- Set inbound address flow: /docs/operations/setInboundAddressFlow.md
- Get inbound overview: /docs/operations/getInboundOverview.md
- List regions: /docs/operations/listRegions.md
- Configure region [self-hosted]: /docs/operations/configureRegion.md
- Discover region: /docs/operations/discoverRegion.md
- Provision region [self-hosted]: /docs/operations/provisionRegion.md
- Configure region auto validation [self-hosted]: /docs/operations/configureRegionAutoValidation.md
- List workspace members: /docs/operations/listWorkspaceMembers.md
- Invite workspace member [deprecated]: /docs/operations/inviteWorkspaceMember.md
- List workspace invitations: /docs/operations/listWorkspaceInvitations.md
- Create workspace invitation: /docs/operations/createWorkspaceInvitation.md
- Revoke workspace invitation: /docs/operations/revokeWorkspaceInvitation.md
- List activity: /docs/operations/listActivity.md
- Get current identity: /docs/operations/getCurrentIdentity.md
- List agent tokens: /docs/operations/listAgentTokens.md
- Create agent token: /docs/operations/createAgentToken.md
- Revoke agent token: /docs/operations/revokeAgentToken.md
- Exchange agent setup token: /docs/operations/exchangeAgentSetupToken.md
- Start agent device authorization: /docs/operations/startAgentDeviceAuthorization.md
- Poll agent device token: /docs/operations/pollAgentDeviceToken.md
- Receive cloud formation sns event [SNS webhook]: /docs/operations/receiveCloudFormationSnsEvent.md
- Receive ses sns event [SNS webhook]: /docs/operations/receiveSesSnsEvent.md
