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

## Check email

`POST /v1/emails/check`

Read-only 0–100 advisory score, not an inbox-placement probability or admission decision. Supply one draft (HTML or text), outbound email ID, or campaign ID. Uses visible retained content, cached From-domain facts, and workspace reputation for unrestricted readers. No DNS/asset fetches or paid screen. Scores use current evidence, not a historical delivery verdict. HTML has the preview lint’s 256 KiB UTF-8 and tree budgets. Marketing drafts are checked as supplied; Nightmail adds the unsubscribe headers, the link and the workspace’s postal address to campaigns and to marketing mail it sent, so those are checked as sent. Each finding’s fix is one plain sentence and fixIn says where it is made. MIME bytes are estimated.

Operation ID: `checkEmail`

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


### Request body

One of 3:

#### Variant 1: SendabilityDraft

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `from` | string | yes |  |
| `fromName` | string | no |  |
| `to` | string or string[] | no |  |
| `subject` | string | yes |  |
| `html` | string | no |  |
| `text` | string | no |  |
| `stream` | string | yes |  |
| `headers` | object | no | Header name to value. May include observed or planned transport headers; not trusted as authentication evidence. |
| `attachments` | object[] | no | Optional metadata only: decoded byte size, never attachment bytes or fetch URLs. |
| `attachments[].filename` | string | yes |  |
| `attachments[].contentType` | string | yes |  |
| `attachments[].size` | integer | yes |  |

#### Variant 2

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `emailId` | string | yes |  |

#### Variant 3

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `campaignId` | string | yes |  |

### TypeScript SDK

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

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

const result = await checkEmail({
  client,
  body: {
    "from": "sender@example.com",
    "subject": "Hello from Nightmail",
    "stream": "transactional"
  },
  throwOnError: true,
});

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

### cURL

```sh
curl --request POST \
  --url 'https://nightmail.dev/v1/emails/check' \
  --header "Authorization: Bearer $NIGHTMAIL_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "from": "sender@example.com",
  "subject": "Hello from Nightmail",
  "stream": "transactional"
}'
```

### 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 |
| --- | --- | --- | --- |
| `score` | integer | yes |  |
| `grade` | string | yes |  |
| `domainId` | string or null | yes | The From domain’s ID (getDomain) when it is one of this workspace’s domains: where a finding with fixIn domain is fixed. |
| `categories` | object[] | yes |  |
| `categories[].id` | string | yes |  |
| `categories[].score` | integer | yes |  |
| `categories[].weight` | integer | yes |  |
| `findings` | object[] | yes |  |
| `findings[].ruleId` | string | yes |  |
| `findings[].category` | string | yes |  |
| `findings[].severity` | string | yes |  |
| `findings[].title` | string | yes |  |
| `findings[].detail` | string | yes |  |
| `findings[].fix` | string | yes | What to do, in one short sentence of everyday words. The title and the detail name the header, record or standard. |
| `findings[].fixIn` | string | yes | Where the fix is made: the From domain’s DNS records and setup (domain), the workspace’s settings (workspace), how much and to whom you send (sending), or the message itself (message). |
| `findings[].evidence` | object | 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. |
