---
title: "Create a sending domain's DNS records"
url: https://docs.corefinity.com/api/reference/site-settings/create-site-email-dns-records
type: endpoint
last_updated: 2026-11-13
feature: email
related:
  - https://docs.corefinity.com/guides/sites/site-settings/outbound-email.md
  - https://docs.corefinity.com/mcp/tools/corestack_email_apply_dns.md
---
# Create a sending domain's DNS records

Writes the sending domain's DNS records into the Cloudflare zone of a connected Cloudflare account, while the
domain waits for DNS; `mx: true` also writes the optional MX records. A record that could not be written
leaves its guidance in `email.error`. Try-it is off because the request changes live DNS.

```http
POST /api/corestack/sites/{site}/email/dns
```

- Scope: `write`
- Two-factor: required on your account (all)
- Rate limit: 12 a minute
- Try it in the console: off. It has not been cleared for the console. Copy the request and run it yourself when you are sure.

## Path parameters

- `site` (integer, required): The id of a site row. A website's production site and each of its environments has its own id. Digits only.

## Body

- `domain` (string): A sending domain of the site, by its name or its `id`. Left out, the default.
- `mx` (boolean): True to write the optional MX records too.

## Request

### curl

```bash
curl -X POST https://manage.corefinity.com/api/corestack/sites/1042/email/dns \
  -H "Authorization: Bearer $COREFINITY_TOKEN" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{}'
```

### PHP

```php
use Illuminate\Support\Facades\Http;

$response = Http::withToken(env('COREFINITY_TOKEN'))
    ->acceptJson()
    ->post('https://manage.corefinity.com/api/corestack/sites/1042/email/dns', (object) []);

$data = $response->json();
```

### Node

```javascript
const res = await fetch('https://manage.corefinity.com/api/corestack/sites/1042/email/dns', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.COREFINITY_TOKEN}`,
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({}),
});

// An answer with no body (204) has nothing to parse.
const text = await res.text();
const data = text && JSON.parse(text);
```

### Python

```python
import os
import requests

res = requests.post(
    "https://manage.corefinity.com/api/corestack/sites/1042/email/dns",
    headers={
        "Authorization": f"Bearer {os.environ['COREFINITY_TOKEN']}",
        "Accept": "application/json",
    },
    json={},
)

data = res.json() if res.content else None
```

## Responses

### 200 The records were written, as far as they could be.

```json
{
  "email": {
    "add": {
      "allowed": true,
      "count": 1,
      "default_prefix": "mg",
      "max": 5,
      "reason": null
    },
    "cloudflare": {
      "can_write_records": true,
      "connected": true,
      "written_at": "2026-11-03T09:16:40Z",
      "zone": {
        "id": "example-zone-id",
        "name": "harbourandfinch.example.com"
      }
    },
    "default_domain": "mg.harbourandfinch.example.com",
    "domains": [
      {
        "active": true,
        "added_at": "2026-11-03T09:16:40Z",
        "added_by": "Daniel Reyes",
        "can_make_default": false,
        "can_remove": true,
        "can_rotate": true,
        "can_test": false,
        "cloudflare": {
          "can_write_records": true,
          "connected": true,
          "written_at": "2026-11-03T09:16:40Z",
          "zone": {
            "id": "example-zone-id",
            "name": "harbourandfinch.example.com"
          }
        },
        "error": null,
        "from_domain": "harbourandfinch.example.com",
        "id": 3101,
        "is_default": true,
        "last_checked_at": "2026-11-03T09:16:40Z",
        "last_test": null,
        "make_default_reason": null,
        "operation_id": 5120,
        "records": [
          {
            "cloudflare": {
              "record_id": "example-record-id",
              "written_at": "2026-11-03T09:16:40Z"
            },
            "found": null,
            "name": "mg.harbourandfinch.example.com",
            "priority": null,
            "purpose": "spf",
            "required": true,
            "state": "missing",
            "type": "TXT",
            "value": "v=spf1 include:mail.example.net ~all"
          },
          {
            "cloudflare": {
              "record_id": "example-record-id",
              "written_at": "2026-11-03T09:16:40Z"
            },
            "found": null,
            "name": "pic._domainkey.mg.harbourandfinch.example.com",
            "priority": null,
            "purpose": "dkim",
            "required": true,
            "state": "missing",
            "type": "TXT",
            "value": "k=rsa; p=SYNTHETIC-DKIM-PUBLIC-KEY"
          },
          {
            "cloudflare": {
              "record_id": "example-record-id",
              "written_at": "2026-11-03T09:16:40Z"
            },
            "found": null,
            "name": "mg.harbourandfinch.example.com",
            "priority": 10,
            "purpose": "mx",
            "required": false,
            "state": "missing",
            "type": "MX",
            "value": "mxa.eu.mail.example.net"
          },
          {
            "cloudflare": {
              "record_id": "example-record-id",
              "written_at": "2026-11-03T09:16:40Z"
            },
            "found": null,
            "name": "mg.harbourandfinch.example.com",
            "priority": 10,
            "purpose": "mx",
            "required": false,
            "state": "missing",
            "type": "MX",
            "value": "mxb.eu.mail.example.net"
          },
          {
            "cloudflare": {
              "record_id": "example-record-id",
              "written_at": "2026-11-03T09:16:40Z"
            },
            "found": null,
            "name": "email.mg.harbourandfinch.example.com",
            "priority": null,
            "purpose": "tracking",
            "required": true,
            "state": "missing",
            "type": "CNAME",
            "value": "eu.mail.example.net"
          }
        ],
        "remove_reason": null,
        "sender": {
          "address": "noreply@harbourandfinch.example.com",
          "name": "Harbour & Finch"
        },
        "sending_domain": "mg.harbourandfinch.example.com",
        "state": "pending_dns",
        "state_label": "Waiting for DNS",
        "test_reason": "Test emails can be sent once the sending domain is verified",
        "verified_at": null
      }
    ],
    "error": null,
    "last_checked_at": "2026-11-03T09:16:40Z",
    "mailpit": null,
    "operation": null,
    "records": [
      {
        "cloudflare": {
          "record_id": "example-record-id",
          "written_at": "2026-11-03T09:16:40Z"
        },
        "found": null,
        "name": "mg.harbourandfinch.example.com",
        "priority": null,
        "purpose": "spf",
        "required": true,
        "state": "missing",
        "type": "TXT",
        "value": "v=spf1 include:mail.example.net ~all"
      },
      {
        "cloudflare": {
          "record_id": "example-record-id",
          "written_at": "2026-11-03T09:16:40Z"
        },
        "found": null,
        "name": "pic._domainkey.mg.harbourandfinch.example.com",
        "priority": null,
        "purpose": "dkim",
        "required": true,
        "state": "missing",
        "type": "TXT",
        "value": "k=rsa; p=SYNTHETIC-DKIM-PUBLIC-KEY"
      },
      {
        "cloudflare": {
          "record_id": "example-record-id",
          "written_at": "2026-11-03T09:16:40Z"
        },
        "found": null,
        "name": "mg.harbourandfinch.example.com",
        "priority": 10,
        "purpose": "mx",
        "required": false,
        "state": "missing",
        "type": "MX",
        "value": "mxa.eu.mail.example.net"
      },
      {
        "cloudflare": {
          "record_id": "example-record-id",
          "written_at": "2026-11-03T09:16:40Z"
        },
        "found": null,
        "name": "mg.harbourandfinch.example.com",
        "priority": 10,
        "purpose": "mx",
        "required": false,
        "state": "missing",
        "type": "MX",
        "value": "mxb.eu.mail.example.net"
      },
      {
        "cloudflare": {
          "record_id": "example-record-id",
          "written_at": "2026-11-03T09:16:40Z"
        },
        "found": null,
        "name": "email.mg.harbourandfinch.example.com",
        "priority": null,
        "purpose": "tracking",
        "required": true,
        "state": "missing",
        "type": "CNAME",
        "value": "eu.mail.example.net"
      }
    ],
    "sender": {
      "address": "noreply@harbourandfinch.example.com",
      "name": "Harbour & Finch"
    },
    "sending_domain": "mg.harbourandfinch.example.com",
    "state": "pending_dns",
    "state_label": "Waiting for DNS",
    "store_mapping": null,
    "test": {
      "last_sent_at": null,
      "last_to": null,
      "remaining_today": 20
    },
    "verified_at": null
  },
  "written": 5
}
```

### 401 No token, or a token that is not valid.

```json
{
  "message": "Unauthenticated."
}
```

### 403 The token lacks the scope (`scope_required`, with the `scope` to use), your company requires two-factor authentication and you have not set it up, or your account has no company that can use Managed Clusters, for example because the company was closed (`company_unavailable` or `company_not_enabled`, whichever the route checks first). For Managed Clusters routes; any other route uses `ForbiddenScopeOrTwoFactor`.

```json
{
  "code": "company_unavailable",
  "message": "Your company is unavailable.",
  "reason": "company_unavailable"
}
```

### 404 The site id does not exist or is a site you cannot change, the feature is not on for your company (`feature_off`), or the site has no sending domain by that name or id (`tenant_mismatch`).

```json
{
  "code": "feature_off",
  "message": "Not found.",
  "reason": "feature_off"
}
```

### 409 The records cannot be written. `reason` says why: `not_connected` (your company has no connected Cloudflare account), `no_zone` (the domain is in none of the connected account's zones, or Cloudflare is switched off for the site), `deleted`, `provisioning` or `managed_elsewhere`.

```json
{
  "code": "no_zone",
  "message": "Cloudflare is switched off for this site",
  "reason": "no_zone"
}
```

### 422 `mx` is not true or false (`invalid`), or the domain is not waiting for DNS (`state`).

```json
{
  "code": "state",
  "message": "The records can be added while the domain waits for DNS",
  "reason": "state"
}
```

### 429 Too many requests (`rate_limited`). Wait for the number of seconds in `Retry-After`, which `retry_after_seconds` repeats.

```json
{
  "code": "rate_limited",
  "message": "Too many requests. Try again in 60 seconds.",
  "reason": "rate_limited",
  "retry_after_seconds": 60
}
```

## If it is refused

| Status | Reason | What to do |
|---|---|---|
| 401 |  | Send a valid token as `Authorization: Bearer <token>`. |
| 403 | `company_unavailable` | Your company is unavailable. |
| 403 | `scope_required` | Use a token with the scope named in `scope`. |
| 403 | `two_factor_required` | Turn on two-factor on your account, then send again. |
| 404 | `feature_off` | This feature is not on for your organisation yet. |
| 404 | `tenant_mismatch` | The object does not exist or the token may not see it. Check the id. |
| 409 | `no_zone` | The site's domain is not in a connected Cloudflare zone, or Cloudflare is off for the site. Connect the Cloudflare account that holds the zone. |
| 409 | `deleted` | The site, environment or copy has been deleted, or is being deleted. Nothing can be changed on it. Restore a deleted site first if it can still be restored. |
| 409 | `managed_elsewhere` | This site is read-only here. Change it in the control panel that manages it. |
| 409 | `not_connected` | The outside account this needs is not connected for your company. Connect it first; the message names it. |
| 409 | `provisioning` | The site is still being created. Try again in a few minutes. |
| 422 | `state` | What the request acts on is not in a state that allows this. Read the message. |
| 429 | `rate_limited` | Wait for the seconds in `Retry-After`. |

## The same task elsewhere

- Guide: [Outbound email](https://docs.corefinity.com/guides/sites/site-settings/outbound-email.md)
- MCP tool: [`corestack_email_apply_dns`](https://docs.corefinity.com/mcp/tools/corestack_email_apply_dns.md)
