# Nightmail API

Send, receive and reply to email on your own domains. 202 means queued, not delivered.

- [Interactive documentation](/docs)
- [OpenAPI 3.1 JSON](/openapi.json)
- [Agent index](/llms.txt)
- TypeScript package: `@nightmail/sdk`

[API index](/docs.md) · [Inbound threads reference](/docs/tags/inbound-threads.md)

## Reply to inbound thread

`POST /v1/inbound/threads/{threadId}/reply`

Replies to the newest visible message in either direction, breaking time ties by descending message ID. addressId restricts the target and sending address; provide it when the target is linked to more than one visible address. Set replyToMessageId to select an older visible message in this thread. For reviewed replies, pin both IDs and expectedRecipients. A recipient mismatch or a pending outbound parent without a provider Message-ID returns 409.

Operation ID: `replyToInboundThread`

Permission: Needs Send email for the address or inbox.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `threadId` | path | string | yes |  |
| `Idempotency-Key` | header | string | no | Optional. Makes retries safe. Repeating a request with the same key and the same body returns the original result without performing the write again. While the first request with a key is still running, a duplicate returns 409 IDEMPOTENCY_IN_PROGRESS with Retry-After: retry with the same key, never a new one. Reusing a key with a different body returns 409 IDEMPOTENCY_CONFLICT. Keys are scoped to the API key and request path. A send's key is kept at least 30 days from the request, as long as the log of the emails it queued; then it is deleted, and the same key is a new request that sends again. A scheduled send's key is kept at least 60 days, after which a repeat is refused because its time has passed. Without a key, every request is processed, so a retried send can deliver twice. |

### Request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `from` | string | no | Defaults to the public address if configured, otherwise the primary receiving address. Address keys may use only addresses owned by this mailbox. Administrators may use any address on a domain registered in Nightmail for the receiving region; replies still return to whatever address the recipient answers. |
| `text` | string | no |  |
| `html` | string | no |  |
| `attachments` | object or object[] | no | Up to 100 files, 25 MiB combined. Any type Amazon SES delivers (executables and scripts are refused). |
| `replyTo` | string[] | no |  |
| `headers` | object[] | no | Extra MIME headers, 8 KB total. The 15-header limit includes generated headers (two for marketing and any mailbox threading headers). Any name is allowed except headers Nightmail controls: From, Sender, Reply-To, Return-Path, To, Cc, Bcc, Subject, Date, Message-ID, MIME-Version, Content-*, DKIM-*, ARC-*, Authentication-Results, Received*, Resent-*, X-SES-*, List-Unsubscribe*, Auto-Submitted, and reply, receipt, trace and transport headers (Mail-Reply-To, Mail-Followup-To, Followup-To, Disposition-Notification-*, Return-Receipt-To, Errors-To, Bounces-To, Delivered-To, X-Original-To, DomainKey-*, Feedback-ID, TLS-Required, BIMI-*, Autocrypt*, OpenPGP). In-Reply-To and References must be <id@domain> Message-IDs and thread the message in the recipient's mail client. |
| `headers[].name` | string | yes |  |
| `headers[].value` | string | yes |  |
| `autoSubmitted` | string | no | Adds an RFC 3834 Auto-Submitted header so other automated systems do not reply to this message. |
| `addressId` | string | no | Opaque inbound address ID (mbx_…). |
| `replyToMessageId` | string | no | Nightmail message ID (msg_…) of a visible message in this thread. |
| `expectedRecipients` | object | no | Check the final To, Cc and Bcc against these reviewed address sets; never overrides recipients. A mismatch returns 409 INBOUND_RECIPIENTS_CHANGED. |
| `expectedRecipients.to` | string[] | yes |  |
| `expectedRecipients.cc` | string[] | yes |  |
| `expectedRecipients.bcc` | string[] | yes |  |
| `replyAll` | boolean | no | Also copy everyone else on the original message. |
| `to` | string[] | no | Override the computed recipients. |
| `cc` | string[] | no |  |
| `bcc` | string[] | no |  |
| `subject` | string | no | Defaults to "Re: <original subject>". |
| `quote` | boolean | no | Append the original message as quoted text. |
| `allowAutomated` | boolean | no | Reply even when the original is automated or the recipient is a no-reply address. |

### TypeScript SDK

```ts
import { createClient } from '@nightmail/sdk/client';
import { replyToInboundThread } from '@nightmail/sdk';

const client = createClient({
  baseUrl: 'https://nightmail.dev',
  auth: scheme => scheme.scheme === 'bearer'
    ? process.env.NIGHTMAIL_API_KEY
    : undefined,
});

const result = await replyToInboundThread({
  client,
  path: {
    "threadId": "thread_123"
  },
  body: {
    "attachments": [],
    "replyTo": [],
    "headers": [],
    "replyAll": false,
    "bcc": [],
    "quote": false,
    "allowAutomated": false
  },
  throwOnError: true,
});

console.log(result.data);
```

### cURL

```sh
curl --request POST \
  --url 'https://nightmail.dev/v1/inbound/threads/thread_123/reply' \
  --header "Authorization: Bearer $NIGHTMAIL_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "attachments": [],
  "replyTo": [],
  "headers": [],
  "replyAll": false,
  "bcc": [],
  "quote": false,
  "allowAutomated": false
}'
```

### Responses

| Status | Description | Schema |
| --- | --- | --- |
| `202` | Queued, not yet delivered. | object |
| `400`, `401`, `403`, `404`, `409`, `413`, `422`, `429`, `500`, `503` | Request failed; use error.code and requestId to diagnose. | object |

#### 202: Queued, not yet delivered.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `simulated` | boolean | no |  |
| `id` | string | yes |  |
| `threadId` | string | yes |  |
| `addressIds` | string[] | yes |  |
| `direction` | string | yes |  |
| `status` | string | yes |  |
| `from` | object | yes |  |
| `from.name` | string or null | yes |  |
| `from.address` | string | yes |  |
| `to` | object[] | yes | Addresses in the To header (at most 20 on conversation pages, up to 100 on getInboundMessage). |
| `to[].name` | string or null | yes |  |
| `to[].address` | string | yes |  |
| `toCount` | integer | yes | Total addresses in the To header (may exceed to.length when shortened). |
| `cc` | object[] | yes | Addresses in the Cc header (at most 20 on conversation pages, up to 100 on getInboundMessage). |
| `cc[].name` | string or null | yes |  |
| `cc[].address` | string | yes |  |
| `ccCount` | integer | yes | Total addresses in the Cc header (may exceed cc.length when shortened). |
| `replyTo` | object[] | yes | Addresses in the Reply-To header (at most 20 on conversation pages, up to 100 on getInboundMessage). |
| `replyTo[].name` | string or null | yes |  |
| `replyTo[].address` | string | yes |  |
| `replyToCount` | integer | yes | Total addresses in the Reply-To header (may exceed replyTo.length when shortened). |
| `subject` | string | yes |  |
| `snippet` | string | yes |  |
| `text` | string | yes |  |
| `replyText` | string | yes |  |
| `receivedAt` | string | yes |  |
| `bodyTruncated` | boolean | yes |  |
| `attachmentCount` | integer | yes |  |
| `read` | boolean | yes |  |
| `errorCode` | string or null | yes |  |
| `suppressionReason` | string or null | no | Reason recorded when this send was suppressed. For a multi-recipient send blocked locally, this is the first blocked recipient in To, Cc, Bcc order. |
| `emailId` | string or null | yes |  |
| `messageId` | string or null | yes | RFC Message-ID, not the Nightmail message ID (id). |
| `inReplyTo` | string or null | yes |  |
| `references` | string[] | yes | Message-IDs in the References header (at most 20 on conversation pages, up to 100 on getInboundMessage). |
| `referencesCount` | integer | yes | Total Message-IDs in the References header (may exceed references.length when shortened). |

#### 400, 401, 403, 404, 409, 413, 422, 429, 500, 503: Request failed; use error.code and requestId to diagnose.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `error` | object | yes |  |
| `error.code` | string | yes |  |
| `error.message` | string | yes |  |
| `error.requestId` | string | yes |  |
| `error.field` | string | no |  |
| `error.retryable` | boolean | yes |  |
| `error.resetAt` | string | no | Next capacity change for a Hosted rolling send limit. |
| `error.details` | object[] | no | Every problem found, when there is more than one part, such as rule diagnostics with rule, line, column, message and hint, or a measurement, such as CONTENT_TOO_LARGE_TO_SCREEN with screenedBytes and limitBytes (and index in a batch). |
| `error.required` | object | no | On a 403 permission refusal: what the request needs that this credential lacks. The Nightmail-Required-Permission header says the same. |
