# 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)

## Get inbound message

`GET /v1/inbound/messages/{messageId}`

Returns stored text, attachment metadata, and up to 100 stored addresses per field with exact header counts in toCount, ccCount, replyToCount and referencesCount. Each statement stops after 3 seconds: a request that needs longer is refused with 422 READ_TOO_LARGE. Narrow the dates or filters.

Operation ID: `getInboundMessage`

Permission: Needs Received mail: read for the address it reached, or a sender domain it was addressed to.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `messageId` | path | string | yes |  |
| `addressId` | query | string | no | Opaque inbound address ID (mbx_…). |
| `includeDelivery` | query | string | no | Include delivery details for workspace logs (owner or admin sessions, and API keys with manage permission on all domains, only). |
| `includeAuthentication` | query | string | no | Include the sender authentication results (SPF, DKIM, DMARC) and whether the message is automated (auto-replies, bounces, bulk and list mail). Available to any reader of the message. |
| `includeHtml` | query | string | no |  |
| `includeThread` | query | string | no | Include the conversation it belongs to (thread): up to 50 messages around it that you can read, oldest first, and their count. A key limited to addresses or an inbox reads only the messages on its addresses. |


### TypeScript SDK

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

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

const result = await getInboundMessage({
  client,
  path: {
    "messageId": "message_123"
  },
  throwOnError: true,
});

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

### cURL

```sh
curl --request GET \
  --url 'https://nightmail.dev/v1/inbound/messages/message_123' \
  --header "Authorization: Bearer $NIGHTMAIL_API_KEY"
```

### Responses

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

#### 200: Success

| 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). |
| `addresses` | object[] | no |  |
| `addresses[].id` | string | yes |  |
| `addresses[].address` | string | yes |  |
| `envelopeTo` | string[] | no | SMTP envelope recipients (at most 20 on list pages, up to 100 on getInboundMessage). |
| `envelopeToCount` | integer | no | Total SMTP envelope recipients (may exceed envelopeTo.length when shortened). |
| `region` | string or null | no |  |
| `spam` | boolean | no |  |
| `rawUrl` | string or null | no |  |
| `rawExpiresAt` | string or null | no |  |
| `sentAt` | string or null | no |  |
| `sizeBytes` | integer or null | no |  |
| `headers` | object[] | no |  |
| `headers[].name` | string | yes |  |
| `headers[].value` | string | yes |  |
| `verdicts` | object | no |  |
| `thread` | object or null | no | With includeThread=true: its conversation, as getEmailDetail shows it. |
| `thread.id` | string | yes | The conversation (getInboundThread). |
| `thread.count` | integer | yes | Messages in it that the caller can read. |
| `thread.messages` | object[] | yes | Up to 50 of them around this email, oldest first. |
| `authentication` | object | no | With includeAuthentication=true. |
| `authentication.spf` | string or null | yes |  |
| `authentication.dkim` | string or null | yes |  |
| `authentication.dmarc` | string or null | yes | PASS when the From domain is aligned with a passing SPF or DKIM result. |
| `automated` | boolean | no | With includeAuthentication=true: an auto-reply, bounce, delivery report, or bulk or list mail. Never answer it automatically. |
| `html` | string or null | yes |  |
| `htmlTooComplex` | boolean | yes | With includeHtml=true: the HTML has more elements or deeper nesting than Nightmail parses (20,000 nodes, 256 levels deep). It is returned as stored; prefer text to rendering it. |
| `attachments` | object[] | yes |  |
| `attachments[].id` | string | yes |  |
| `attachments[].filename` | string | yes |  |
| `attachments[].contentType` | string | yes |  |
| `attachments[].size` | integer | yes |  |
| `attachments[].disposition` | string | yes |  |
| `attachments[].contentId` | string or null | yes |  |
| `attachments[].url` | string or null | no |  |

#### 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. |
