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

## List emails

`GET /v1/emails`

Sent emails, newest first. from and to (or since and until) are ISO 8601 times that bound when an email was created, not addresses: filter by sender or recipient address with search. Pages are also bounded by response size and may return fewer than limit emails; follow nextCursor while non-null. 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: `listEmails`

Permission: Needs Sent mail: read for the sender domain.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `cursor` | query | string | no |  |
| `limit` | query | integer | no |  |
| `campaignId` | query | string | no |  |
| `status` | query | string | no | scheduled lists sends waiting for their time; queued includes them. |
| `region` | query | string | no |  |
| `kind` | query | string | no |  |
| `search` | query | string | no | Literal case-insensitive substring of sender, To/Cc/Bcc, subject or email/campaign/provider ID, at least 3 characters: a shorter term is refused with 422 VALIDATION_FAILED. This is how to filter by sender or recipient address. |
| `from` | query | string | no | The start of the time range: emails created at or after this ISO 8601 date-time with Z or an offset, such as 2026-11-01T00:00:00Z. A time, not a sender: filter by sender address with search. since is the same filter by a clearer name; send one of them. |
| `to` | query | string | no | The end of the time range: emails created before this ISO 8601 date-time with Z or an offset. A time, not a recipient: filter by recipient address with search. until is the same filter by a clearer name; send one of them. |
| `since` | query | string | no | The start of the time range, the same filter as from: emails created at or after this ISO 8601 date-time. Send since or from, not both. |
| `until` | query | string | no | The end of the time range, the same filter as to: emails created before this ISO 8601 date-time. Send until or to, not both. |


### TypeScript SDK

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

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

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

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

### cURL

```sh
curl --request GET \
  --url 'https://nightmail.dev/v1/emails' \
  --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[].untrustedContent` | boolean | yes | True for replies and older non-campaign mail of unknown origin: the subject or body may contain received content. |
| `data[].id` | string | yes |  |
| `data[].region` | string | yes |  |
| `data[].campaignId` | string or null | yes |  |
| `data[].from` | string | yes |  |
| `data[].fromName` | string or null | yes |  |
| `data[].kind` | string | yes |  |
| `data[].to` | string[] | yes |  |
| `data[].cc` | string[] | yes |  |
| `data[].bcc` | string[] | yes |  |
| `data[].subject` | string | yes |  |
| `data[].status` | string | yes | A scheduled email is queued, with scheduled true, until it is sent at scheduledAt. |
| `data[].providerId` | string or null | yes |  |
| `data[].simulated` | boolean | yes |  |
| `data[].attemptStartedAt` | string or null | yes |  |
| `data[].errorCode` | string or null | 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[].scheduled` | boolean | yes | True while a scheduled send waits for scheduledAt: it has not started sending, and cancelEmail or rescheduleEmail still apply. At that time it is admitted like a send made then (limits and balance included) and follows the usual lifecycle, or is rejected with the refusal’s code. |
| `data[].scheduledAt` | string or null | yes | When a scheduled send goes (UTC). Also set while queued mail waits to be retried. |
| `data[].createdAt` | string | yes | When the email was submitted; a scheduled send’s moves to the moment it was released at its time. |
| `data[].updatedAt` | string | yes |  |
| `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. |
