# 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 addresses reference](/docs/tags/inbound-addresses.md)

## Create inbound address

`POST /v1/inbound/addresses`

Admin only. Mail arrives once the domain is verified and its receiving MX record is active. Hosted, an address on one of your own domains (or a subdomain of one), verified or still being verified, where nothing receives yet turns receiving on at its host, as addReceivingHost does, and the answer’s receiving names the MX record to publish, the host’s status and whether the domain is verified yet; a host whose mail another provider receives today is refused with RECEIVING_HOST_IN_USE and the call that moves it. A refused request creates nothing, and receiving stays as it was. Permanent addresses claim earlier unrouted mail (kept 30 days) for their address or rules; temporary addresses start empty. Expiry stops new delivery and sending without deleting history.

Operation ID: `createInboundAddress`

Permission: Needs Inboxes: write on the whole workspace. A person needs to be an owner or admin.


### Request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `key` | string or null | no | Stable key you choose (lowercase letters, digits, hyphens). Config files refer to inbox:<key>, webhook:<key> and forward:<name>. |
| `address` | string | yes |  |
| `displayName` | string or null | no |  |
| `publicAddress` | string | no | Permanent addresses only: immutable default From with the same local part on a strict ancestor domain verified for sending with DKIM in the receiving region. Does not change routing or MX. |
| `ttlSeconds` | integer | no | Lease duration in seconds, 60–2592000 (30 days). Omit for a permanent address. Temporary addresses accept plus-tags, not aliases, wildcard rules or historical backfill. Expiry is fixed at creation. |
| `aliases` | string[] | no |  |
| `rules` | string[] | no | Wildcard address patterns, e.g. support+*@acme.com or *@help.acme.com. |
| `metadata` | object | no |  |
| `sendLimits` | object | no | Override the loop guards. Defaults: perRecipientPerHour 20, perThreadPer10Minutes 10. 0 blocks sending. There is no hourly or daily cap per address. |
| `sendLimits.perHour` | integer | no | Deprecated and not enforced: any whole number from 0 is accepted. 0 turns sending off; any other number has no effect. |
| `sendLimits.perDay` | integer | no | Deprecated and not enforced: any whole number from 0 is accepted. 0 turns sending off; any other number has no effect. |
| `sendLimits.perRecipientPerHour` | integer | no |  |
| `sendLimits.perThreadPer10Minutes` | integer | no |  |
| `requireDmarc` | boolean | no | Hold received mail without a DMARC pass for its From domain: it is stored with the unverified label and does not emit message.received. |
| `flow` | object | no | Where the new address’s mail goes, saved with the address in one transaction and one routing version: deliver creates the route for its own address, split adds a two-way rule on it (setInboundAddressFlow changes both later). If any part is refused, nothing is created. Needs what changing routes and rules needs. |
| `flow.endpoints` | object[] | no | New endpoints this change uses, made with it: a refusal or failure makes none of them. |
| `flow.forward` | object | no | A new forward, made after the address: its recipient is asked by the new address. deliver and split may name it at once (forward:<name>; <name> in split params): mail received from the moment they allow it is forwarded, never mail received before. The answer’s forward says whether they were emailed. |
| `flow.deliver` | string or string or string[] or null | no | Where the address's mail goes: the destinations of the route for its own address, as createRoute takes them (inbox, webhook and forward IDs or keys, [] to keep it without an inbox, or 'drop'). Creates the route when there is none; null deletes it. |
| `flow.split` | object | no | Adds a two-way rule on the new address. Its params may name the new address as inbox:<key>. |

### TypeScript SDK

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

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

const result = await createInboundAddress({
  client,
  body: {
    "address": "example",
    "aliases": [],
    "rules": [],
    "metadata": {},
    "requireDmarc": false
  },
  throwOnError: true,
});

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

### cURL

```sh
curl --request POST \
  --url 'https://nightmail.dev/v1/inbound/addresses' \
  --header "Authorization: Bearer $NIGHTMAIL_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "address": "example",
  "aliases": [],
  "rules": [],
  "metadata": {},
  "requireDmarc": false
}'
```

### Responses

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

#### 201: Success

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | yes |  |
| `key` | string or null | yes | Stable key you choose (lowercase letters, digits, hyphens). Config files refer to inbox:<key>, webhook:<key> and forward:<name>. |
| `address` | string | yes |  |
| `displayName` | string or null | yes |  |
| `domain` | string | yes |  |
| `aliases` | string[] | yes |  |
| `rules` | string[] | yes |  |
| `publicAddress` | string or null | yes | Send-only address used as the default From. Null to send from the receiving address. |
| `metadata` | object | yes |  |
| `origin` | string | yes |  |
| `createdAt` | string | yes |  |
| `updatedAt` | string | yes |  |
| `expiresAt` | string or null | yes | UTC lease expiry, or null for a permanent address. After expiry, new delivery and sending stop. History stays readable and the address remains reserved until an admin deletes it. |
| `stats` | object | yes |  |
| `stats.threads` | integer | yes |  |
| `stats.unreadThreads` | integer | yes |  |
| `stats.lastMessageAt` | string or null | yes |  |
| `sendLimits` | object | yes | Loop guards against runaway agents and reply loops: messages to one recipient per hour, and in one conversation per 10 minutes. The workspace’s sending limits apply on top; there is no hourly or daily cap per address. |
| `sendLimits.perHour` | integer | yes | Deprecated and not enforced: an address has no hourly send cap. The value last set (100 if never set); 0 means sending is off. |
| `sendLimits.perDay` | integer | yes | Deprecated and not enforced: an address has no daily send cap. The value last set (1000 if never set); 0 means sending is off. |
| `sendLimits.perRecipientPerHour` | integer | yes |  |
| `sendLimits.perThreadPer10Minutes` | integer | yes |  |
| `requireDmarc` | boolean | yes | When true, received mail without a DMARC pass for its From domain is stored with the unverified label and does not emit message.received. |
| `kind` | string | yes | inbox: an agent inbox; manage it with /v1/inboxes. |
| `receiving` | object | no | Present while the host doesn’t route mail here yet: hosted, an address on one of your own domains, verified or still being verified, turns receiving on at its host if it was off. |
| `receiving.domainId` | string | yes | The domain the address is on (receiving hosts: /v1/inbound/domains/{id}/hosts). |
| `receiving.host` | string | yes | Where the address receives. |
| `receiving.turnedOn` | boolean | yes | Whether creating the address turned receiving on at this host (it didn’t receive mail before). |
| `receiving.status` | string | yes | The host’s receiving status now: waiting_for_mx until its MX record is live (poll getInboundDomain or listReceivingHosts). |
| `receiving.verified` | boolean | yes | Whether the domain is verified. Until it is (its DNS records: getDomain), mail waits even with the MX record live. |
| `receiving.dns` | object[] | yes | The MX record to publish at the host, if it isn’t already: mail arrives once it is. |
| `forward` | object | no | The forward flow.forward made, as getEndpoint returns it. |
| `forward.id` | string | yes | Endpoint ID: mwh_… for a webhook, con_… for Slack, Discord or a forward. Routes list webhooks and forwards by ID. |
| `forward.name` | string | yes | Endpoint name, unique in the workspace across every type. Rules call endpoints.<name>(…). |
| `forward.type` | string | yes |  |
| `forward.status` | string | yes | ready: callable. pending: a forward waiting for its recipient to confirm. expired: the confirmation link lapsed. declined: the recipient declined or stopped forwards. paused: deliveries are held. |
| `forward.call` | string | yes | How a rule calls it. |
| `forward.target` | string | yes | Where it delivers. Slack, Discord and webhook URLs are write-only; only the last four characters are shown. |
| `forward.policy` | object | yes |  |
| `forward.expiresAt` | string or null | yes | When a pending forward confirmation link expires. |
| `forward.requestFrom` | string or null | yes | A forward: the address that emailed its recipient to confirm. null when none was asked (preverified) and for other types. |
| `forward.nextStep` | string | yes | What to do next, for people and agents. |
| `forward.createdAt` | string | yes |  |
| `forward.confirmation` | string | yes | emailed: its recipient was asked to confirm (requestFrom names who asked); skipped: preverified, ready at once. |

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