# 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) · [Agent inboxes reference](/docs/tags/agent-inboxes.md)

## List inbox messages

`GET /v1/inboxes/{id}/messages`

Oldest first, in commit order. Without after, the page starts at the first message, so mail that arrived before the call is included. With wait, the call holds until a matching message arrives or the time runs out, and answers as soon as the message is stored; pass the returned cursor as after on the next call. Pages are also bounded by response size and may return fewer than limit messages while hasMore is true; to returns at most 20 addresses with the total in toCount. Junk, unverified and held mail never wake a waiter: list them with include=held. Each waited second counts as one request against the key’s per-minute budget. Filtered queries: Each statement stops after 5 seconds: a request that needs longer is refused with 422 READ_TOO_LARGE. Narrow the dates or filters.

Operation ID: `listInboxMessages`

Permission: Needs Received mail: read for the address or inbox.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes |  |
| `after` | query | string | no | cursor from a previous response. Omit to start at the first message. |
| `wait` | query | integer or null | no | Seconds to wait for a message when none is available yet (0–30). The call returns as soon as one arrives. |
| `limit` | query | integer | no |  |
| `folder` | query | string or string | no | Select one folder. In a folder, after and cursor are UIDs, not delivery cursors. |
| `flagged` | query | string | no |  |
| `from` | query | string | no | Only messages from this sender address. |
| `subjectContains` | query | string | no | Only messages whose subject contains this text, ignoring case. |
| `unread` | query | string | no |  |
| `include` | query | string | no | Also list junk, unverified and held mail. Ignored with wait. |
| `extract` | query | string | no | Extract one-time codes, links or both into each message’s extract field. |


### TypeScript SDK

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

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

const result = await listInboxMessages({
  client,
  path: {
    "id": "resource_123"
  },
  throwOnError: true,
});

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

### cURL

```sh
curl --request GET \
  --url 'https://nightmail.dev/v1/inboxes/resource_123/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[].cursor` | string | yes | Pass as after to continue after this message. |
| `data[].from` | object | yes | The claimed sender. Check auth before trusting it. |
| `data[].to` | object[] | yes | Addresses in the To header (at most 20 on list pages, up to 100 on getInboxMessage). |
| `data[].toCount` | integer | yes | Total addresses in the To header (may exceed to.length when shortened). |
| `data[].subject` | string | yes |  |
| `data[].snippet` | string | yes |  |
| `data[].receivedAt` | string | yes | When the sending server handed it over (SES received it). |
| `data[].storedAt` | string | yes | When the write that stored it in Nightmail committed, on the clock servedAt uses. |
| `data[].processingMs` | integer or null | yes | Milliseconds from the receipt reaching Nightmail to storedAt: fetching, parsing, routing and storing the message. Null for mail that came another way (simulated, sent, copied). |
| `data[].read` | boolean | yes |  |
| `data[].flags` | string[] | yes |  |
| `data[].labels` | string[] | yes |  |
| `data[].folders` | object[] | yes |  |
| `data[].additionalFolders` | object[] | yes |  |
| `data[].modseq` | string | yes |  |
| `data[].uid` | number or null | yes |  |
| `data[].uidValidity` | number or null | yes |  |
| `data[].junk` | boolean | yes | SES judged this message spam. |
| `data[].held` | string or null | yes | null when delivered; quota or expired when stored but held. |
| `data[].attachmentCount` | number | yes |  |
| `data[].auth` | object | yes | SES verdicts for the sender: PASS, FAIL, GRAY or NONE. |
| `data[].simulated` | boolean | yes | Created by POST /v1/inboxes/{id}/simulate, not received over SMTP. |
| `data[].hiddenContent` | boolean | yes | Best-effort detection of hidden, styled or invisible content. False does not guarantee visibility. |
| `data[].extract` | object | yes | Filled when requested with extract. |
| `cursor` | string | yes | Pass as after on the next call; unchanged when data is empty. |
| `hasMore` | boolean | yes |  |
| `servedAt` | string | yes | When this page was read, on the clock storedAt uses: servedAt minus a message’s storedAt is how long it took to reach you after it was stored. |

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