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

## List inbound messages

`GET /v1/inbound/messages`

Newest first; default inbound. Unassigned stored mail is visible only to a workspace administrator without an address filter. Pages are also bounded by response size and may return fewer than limit messages; pass nextCursor as cursor to continue. With includeDelivery=true, to and envelopeTo return at most 20 items with total counts in toCount and envelopeToCount. 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: `listInboundMessages`

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

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `addressId` | query | string | no | Opaque inbound address ID (mbx_…). |
| `cursor` | query | string | no | Opaque cursor from the preceding page, with the same filters. |
| `limit` | query | integer | no |  |
| `includeDelivery` | query | string | no | Include delivery details for workspace logs (owner or admin sessions, and API keys with manage permission on all domains, only). |
| `region` | query | string | no |  |
| `threadId` | query | string | no |  |
| `direction` | query | string | no |  |
| `q` | query | string | no |  |


### TypeScript SDK

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

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

const result = await listInboundMessages({
  client,
  throwOnError: true,
});

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

### cURL

```sh
curl --request GET \
  --url 'https://nightmail.dev/v1/inbound/messages' \
  --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 |
| --- | --- | --- | --- |
| `data` | object[] | yes |  |
| `data[].id` | string | yes |  |
| `data[].threadId` | string | yes |  |
| `data[].addressIds` | string[] | yes |  |
| `data[].direction` | string | yes |  |
| `data[].status` | string | yes |  |
| `data[].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. |
| `data[].subject` | string | yes |  |
| `data[].snippet` | string | yes |  |
| `data[].receivedAt` | string | yes |  |
| `data[].attachmentCount` | integer | yes |  |
| `data[].from` | object | yes |  |
| `data[].addresses` | object[] | no |  |
| `data[].envelopeTo` | string[] | no | SMTP envelope recipients (at most 20 on list pages, up to 100 on getInboundMessage). |
| `data[].envelopeToCount` | integer | no | Total SMTP envelope recipients (may exceed envelopeTo.length when shortened). |
| `data[].region` | string or null | no |  |
| `data[].spam` | boolean | no |  |
| `data[].to` | object[] | no | Addresses in the To header (at most 20 on list pages). |
| `data[].toCount` | integer | no | Total addresses in the To header (may exceed to.length when shortened). |
| `nextCursor` | string or null | yes |  |

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