# Domains API

Manage sending domains, DNS verification, inbound receiving flags, tracking preferences, TLS mode, one-click DNS apply, and DMARC/BIMI guidance.

Base URL: `https://api.groundmail.dev`

Auth:

```http
Authorization: Bearer gm_...
```

---

## Create a domain

`POST /domains`

```bash
curl -X POST https://api.groundmail.dev/domains \
  -H "Authorization: Bearer $GROUNDMAIL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "name": "mail.example.com" }'
```

Success response:

```json
{
  "domain": {
    "id": "d_123",
    "name": "mail.example.com",
    "status": "pending",
    "created_at": "2026-07-26T00:00:00.000Z",
    "verified_at": null,
    "open_tracking": false,
    "click_tracking": false,
    "tracking_status": "disabled",
    "tracking_error": null,
    "tls_mode": "opportunistic"
  },
  "records": [
    {
      "type": "TXT",
      "host": "_groundmail.mail.example.com",
      "value": "groundmail-verify=...",
      "purpose": "Domain ownership"
    }
  ]
}
```

### Subdomain or main domain

We recommend sending from a subdomain of your company's domain, such as `mail.example.com`. Your app's email builds its own reputation, and your team's mailboxes and the DNS records already on `example.com` stay as they are.

A main domain (`example.com`, `example.co.uk`) works too:

- **No SPF record.** We don't ask for one: your mail passes SPF on the return-path subdomain (`rp.example.com`), so the SPF record your team's email uses stays exactly as it is.
- **Your DMARC record stays.** If `_dmarc.example.com` already has a DMARC record, it comes back with `"already_set": true` and its current value. There is nothing to add or change; one-click apply never replaces or duplicates it.

```json
{
  "type": "TXT",
  "host": "_dmarc.example.com",
  "value": "v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com",
  "purpose": "DMARC",
  "already_set": true
}
```

To give the new domain to one of your [tenants](https://docs.groundmail.dev/tenants), include `"tenant": "cust_8412"`. Only that tenant can then send from it, and the domain object carries `"tenant": "cust_8412"`. `GET /domains?tenant=cust_8412` lists one tenant's domains; a key limited to one tenant only sees and adds its tenant's. Tenants are on the pay-as-you-go and Dedicated plans.

To request inbound receiving during creation, include `"inbound_enabled": true`. The response will also include `inbound_records` (MX) and `inbound_note`. Full receiving flow: [Inbound email API](https://docs.groundmail.dev/inbound).

Expected DNS records for `mail.example.com` (after create syncs with the mail server):

- ownership TXT: `_groundmail.mail.example.com`
- DKIM TXT: selector host such as `ss-abc123._domainkey.mail.example.com` with the real public key
- return-path CNAME: `rp.mail.example.com` → `rp.groundmail.dev` (DNS only / not proxied)
- SPF TXT on `mail.example.com`: `v=spf1 include:spf.groundmail.dev ~all` (subdomains only; a main domain gets no SPF record)
- DMARC starter record, or your existing DMARC record marked `already_set`

Groundmail registers the domain on the transactional mail server at create time and replaces placeholder DKIM with the real signing records before apply/verify.

### Domain name rules

`name` must be a hostname such as `example.com` or `mail.example.com`. Groundmail lowercases it and ignores a leading `https://`, any path, and a trailing dot. It must have at least two labels of letters, digits and hyphens (1–63 characters each, no leading or trailing hyphen), a TLD of letters, and be at most 253 characters. Spaces, underscores and other characters are rejected with **400** `validation_error`:

```json
{ "error": { "message": "That doesn't look like a domain name. Enter something like mail.example.com.", "code": "validation_error" } }
```

### Cross-workspace claim conflict

If the domain is already attached to another Groundmail workspace, the API returns **409** with claim instructions:

```json
{
  "error": {
    "message": "Domain already belongs to another Groundmail team. Remove it from the current team or contact support to claim it.",
    "code": "conflict",
    "details": {
      "reason": "domain_claim_required",
      "domain": "example.com",
      "instructions": [
        "Ask the current Groundmail workspace admin to remove the domain if you still have access.",
        "If you own the domain but no longer control the original workspace, contact support and include proof of DNS control."
      ]
    }
  }
}
```

### Domains that can never be verified

Some names can't be verified by anyone, so adding one returns **400** `validation_error` straight away, with a message that says why and what to do instead. The dashboard shows the same message as you type.

| What you added | Example | `details.reason` |
|----------------|---------|------------------|
| A public email provider, or a subdomain of one | `gmail.com`, `outlook.com`, `mail.gmail.com` | `public_mailbox_domain` |
| A temporary inbox service | `mailinator.com` | `public_mailbox_domain` |
| A free subdomain from a hosting or app-building platform | `your-app.vercel.app`, `your-site.netlify.app`, `you.github.io` | `public_mailbox_domain` |
| An example name | `your-domain.com`, `example.com`, `yourcompany.com` | `placeholder_domain` |

Only the email provider or the platform can add DNS records under its own domain, so these can't prove they're yours. Use a domain you own, such as `yourcompany.com` or `mail.yourcompany.com`. If your app is on Vercel and you have a domain there, [Connect Vercel](https://docs.groundmail.dev/integrations#vercel) adds the records for you. No domain yet? You can send test emails to your own address from the sandbox sender without one.

```json
{
  "error": {
    "message": "You can't send from gmail.com. gmail.com belongs to Google. An app can't send as an @gmail.com address, and inboxes would reject the mail. Use a domain you own.",
    "code": "validation_error",
    "details": { "reason": "public_mailbox_domain", "domain": "gmail.com" }
  }
}
```

```json
{
  "error": {
    "message": "You can't add DNS records to vercel.app. vercel.app belongs to Vercel, so the records that prove the domain is yours can't be added there. Send from a domain you own instead, like myapp.com or mail.myapp.com.",
    "code": "validation_error",
    "details": { "reason": "public_mailbox_domain", "domain": "myapp.vercel.app" }
  }
}
```

A domain that isn't registered yet is **not** refused: you can add it while you're buying it, and it verifies once it's yours and the DNS records are in place.

### Domain unavailable

A domain that can't be used with Groundmail returns **403** when you add or verify it. Contact support@groundmail.dev if you think this is a mistake.

```json
{
  "error": {
    "message": "This domain can't be used with Groundmail. Contact support@groundmail.dev if you think this is a mistake.",
    "code": "forbidden",
    "details": { "reason": "domain_unavailable", "domain": "example.com" }
  }
}
```

---

## Get a domain

`GET /domains/{id}`

Returns the domain, required DNS records, inbound MX guidance, and best-effort DMARC/BIMI analysis:

```json
{
  "domain": {
    "id": "d_123",
    "name": "example.com",
    "status": "verified",
    "created_at": "2026-07-26T00:00:00.000Z",
    "verified_at": "2026-07-26T00:05:00.000Z",
    "open_tracking": true,
    "click_tracking": false,
    "tracking_status": "active",
    "tracking_error": null,
    "tls_mode": "enforced",
    "inbound_enabled": true,
    "inbound_status": "active",
    "inbound_error": null,
    "blocklists": {
      "status": "clear",
      "checked_at": "2026-10-30T13:30:04.000Z",
      "names": ["example.com"],
      "main_domain": "example.com",
      "listings": [],
      "removed": [],
      "unanswered_lists": []
    }
  },
  "records": [],
  "inbound_records": [
    {
      "type": "MX",
      "host": "example.com",
      "priority": 10,
      "value": "mx.groundmail.dev",
      "purpose": "Inbound receiving"
    }
  ],
  "inbound_note": "Inbound receiving requires pointing this hostname's MX record to Groundmail. That conflicts with any existing mailbox provider on the same hostname, so use a dedicated subdomain such as inbound.example.com when Google Workspace or Microsoft 365 should keep handling your main mailboxes.",
  "analysis": {
    "dmarc": {
      "host": "_dmarc.example.com",
      "configured": true,
      "record": "v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com",
      "policy": "quarantine",
      "rua": ["mailto:dmarc@example.com"],
      "guidance": "DMARC is enforced. Keep report mailboxes monitored and tighten alignment as you roll out BIMI."
    },
    "bimi": {
      "host": "default._bimi.example.com",
      "configured": false,
      "record": null,
      "location": null,
      "authority": null,
      "requires_dmarc_enforcement": false,
      "guidance": "Optional: add a BIMI record at default._bimi once your branded SVG logo and optional VMC are ready."
    }
  }
}
```

### Blocklist monitoring

Every day we check each verified domain on the domain blocklists inboxes use: **Spamhaus DBL**, **SURBL** and **URIBL**. A subdomain is checked under two names, itself (`mail.example.com`) and its main domain (`example.com`), because the lists mostly name main domains and inboxes check the main domain. A main domain you added yourself is one name.

When either name is added to a list, every account owner gets an email naming the list, the reason and where to request removal, and a Slack message posts if [Slack alerts](https://docs.groundmail.dev/integrations#slack) are connected. When it comes off, you get a short "removed" email. You hear about each change once, not every day, and one alert covers every domain under the same main domain. A listing never pauses sending.

The result is on every domain as `blocklists` (`GET /domains`, `GET /domains/{id}`):

| Field | Meaning |
|-------|---------|
| `status` | `listed`, `clear`, or `unknown` (before the first check, for a domain that is not verified, or when no list answered) |
| `checked_at` | When the last check ran; `null` until the first one |
| `names` | The names checked: the domain and its main domain, or one name |
| `main_domain` | The main domain |
| `listings` | Current listings, main domain first: `list`, `list_id` (`spamhaus-dbl`, `surbl`, `uribl`), `name`, `reason` (for example `spam domain`), `listed_since`, `info_url` (where to look it up and request removal) |
| `removed` | Recent removals, newest first (up to 5), each with `removed_at` |
| `unanswered_lists` | Lists that did not answer the last check; they are tried again on the next one |

A listed domain looks like this:

```json
"blocklists": {
  "status": "listed",
  "checked_at": "2026-10-30T13:30:04.000Z",
  "names": ["mail.example.com", "example.com"],
  "main_domain": "example.com",
  "listings": [
    {
      "list": "Spamhaus DBL",
      "list_id": "spamhaus-dbl",
      "name": "example.com",
      "reason": "spam domain",
      "listed_since": "2026-10-30T13:30:04.000Z",
      "info_url": "https://check.spamhaus.org/results/?query=example.com"
    }
  ],
  "removed": [],
  "unanswered_lists": []
}
```

In the dashboard, open **Domains → a domain → Overview**: the **Blocklists** row in Domain health shows the result, and **Check now** runs the check again (a few times per domain every 15 minutes). The cause of a listing is usually outside your app email: a hacked page on your website, a form that sends to any address, a marketing or outreach tool sending as your main domain, or a link shortener in your emails. Fix it, then request removal from the list.

### DMARC/BIMI notes

- **DMARC** is recommended for every sending domain.
- **BIMI** is optional, but most mailbox providers expect DMARC enforcement (`p=quarantine` or `p=reject`) before BIMI is effective.
- `analysis` is advisory. It does not block sending, and it does not replace your own deliverability monitoring.

---

## Verify DNS

`POST /domains/{id}`

```json
{ "action": "verify" }
```

When ownership, DKIM, the return-path CNAME and, for a subdomain, SPF are visible in public DNS, Groundmail asks the mail server to re-check delivery DNS and marks the domain verified only when mail-server **DKIM** and **return-path** statuses are OK. That step activates customer-domain DKIM signing (`d=yourdomain`) so DMARC can pass. Without DKIM OK, mail would fall back to the shared pool signer.

A main domain has no SPF record to add, so `checks.spf` is always `true` for it and ownership, DKIM and the return path decide. DMARC is reported back but does not currently block verification. Re-running verify on an already-verified domain re-checks mail-server DKIM (useful after DNS propagation).

Success responses include:

```json
{
  "verified": true,
  "signing_ready": true,
  "mail_server_signing": {
    "dkim_ok": true,
    "return_path_ok": true,
    "dkim_status": "OK",
    "return_path_status": "OK"
  }
}
```

If public DNS looks correct but the mail server has not yet accepted the DKIM TXT or return-path CNAME, verify returns **400** with `mail_server_signing.dkim_ok` / `return_path_ok` reflecting the failure — wait for propagation and verify again.

---

## Apply DNS

`POST /domains/{id}`

Writes the domain's records at its DNS host. `provider` is `cloudflare`, `godaddy`, `vercel`, `netlify`, `digitalocean` or `dnsimple`. Records Groundmail added before are updated in place. For a subdomain, SPF is merged into an existing SPF record at that name rather than replacing it; a main domain's SPF record is never touched. An existing DMARC record is left as it is (`"action": "unchanged"`), never replaced or duplicated.

### Cloudflare via stored dashboard token

```json
{
  "action": "apply",
  "provider": "cloudflare"
}
```

### Cloudflare via inline credentials

```json
{
  "action": "apply",
  "provider": "cloudflare",
  "credentials": {
    "apiToken": "cf_...",
    "zoneId": "..."
  }
}
```

### GoDaddy via a Personal Access Token

```json
{
  "action": "apply",
  "provider": "godaddy",
  "credentials": {
    "apiToken": "gd_pat_..."
  }
}
```

Create the token in the GoDaddy Developer Portal with the `domains.domain:read` and `domains.dns:update` scopes. You can also save it under **Integrations** and omit `credentials` on apply.

GoDaddy is retiring the classic API key and secret for domains. Until it does, `credentials.apiKey` and `credentials.apiSecret` still work in place of `apiToken`.

### Vercel via stored dashboard token

```json
{
  "action": "apply",
  "provider": "vercel"
}
```

The domain must use **Vercel nameservers**. For team-scoped domains, connect Vercel under **Integrations** with an optional team id, or pass `credentials.teamId` / `credentials.vercelTeamId` inline.

### Vercel via inline credentials

```json
{
  "action": "apply",
  "provider": "vercel",
  "credentials": {
    "apiToken": "vercel_...",
    "teamId": "team_..."
  }
}
```

### Netlify, DigitalOcean or DNSimple via the connected account

```json
{
  "action": "apply",
  "provider": "dnsimple"
}
```

Use `"provider": "netlify"`, `"digitalocean"` or `"dnsimple"` after connecting that account under **Integrations**. The domain must use that host's nameservers. To use your own token instead, pass `credentials.apiToken` (for DNSimple also `credentials.accountId`):

```json
{
  "action": "apply",
  "provider": "digitalocean",
  "credentials": {
    "apiToken": "dop_v1_..."
  }
}
```

A DigitalOcean token needs the `domain:read`, `domain:create` and `domain:update` scopes. Netlify has no update call for DNS records, so a record Groundmail changes there is replaced (the new value is added before the old one is removed).

Response shape:

```json
{
  "provider": "godaddy",
  "domain": "example.com",
  "results": [
    {
      "purpose": "DKIM",
      "host": "ss-abc123._domainkey.example.com",
      "action": "created"
    },
    {
      "purpose": "DMARC",
      "host": "_dmarc.example.com",
      "action": "unchanged",
      "detail": "Already set. Nothing to change."
    }
  ]
}
```

---

## Update tracking, inbound, and TLS preferences

`PATCH /domains/{id}`

```bash
curl -X PATCH https://api.groundmail.dev/domains/example.com \
  -H "Authorization: Bearer $GROUNDMAIL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "inbound_enabled": true,
    "open_tracking": true,
    "click_tracking": true,
    "tls_mode": "enforced"
  }'
```

Aliases `openTracking`, `clickTracking`, `tlsMode`, and `inboundEnabled` are also accepted.

### Inbound enablement

- `inbound_enabled: true` marks the domain for receiving.
- Before verification, inbound stays `pending`.
- After verification, Groundmail activates inbound receiving and updates `inbound_status` to `active` or `error`.
- See [Inbound email API](https://docs.groundmail.dev/inbound) for received-email retrieval and `email.received` webhooks.

### Inbound spam filter

- `inbound_spam_threshold` (1–100, or `null` for the default of 10): received mail scoring at or above it gets `spam_status: "spam"`.
- `inbound_spam_action`: `flag` (default) keeps it; `drop` discards it (no stored email, no `email.received` webhook).
- See [Content scanning](https://docs.groundmail.dev/content-scanning#incoming).

### TLS modes

- `opportunistic` — use TLS when the downstream mail path supports it.
- `enforced` — require TLS for the downstream mail path.

### Tracking and TLS preferences

`open_tracking`, `click_tracking`, and `tls_mode` are stored on the domain immediately when you update them.

When open or click tracking is enabled:

1. Groundmail provisions a tracking domain for your hostname.
2. The domain detail response includes a **tracking CNAME** (`ps.yourdomain.com` → `track.groundmail.dev`).
3. Apply and verify DNS so the mail server can rewrite links and inject open pixels.
4. Tracked links and the open pixel are served over HTTPS from `ps.yourdomain.com`. Tracking turns on a few minutes after the CNAME is added, once a certificate is issued for that hostname. There is nothing else to configure.
5. `tracking_dns.ok` in `GET /domains/{id}` reports whether the CNAME resolves in public DNS.
6. The domain's `tracking_status` says whether tracking is actually applied to outgoing mail:

| `tracking_status` | Meaning |
|-------------------|---------|
| `disabled` | Open and click tracking are both off. |
| `pending` | Tracking is on but the CNAME has not been accepted yet, or the certificate for the tracking hostname is still being issued. Mail is sent without tracking; `tracking_error` says what is left. |
| `active` | The CNAME is accepted and the certificate is live. Links are rewritten and the open pixel is added to HTML emails. |
| `error` | Tracking could not be configured, or no certificate could be issued for the tracking hostname. Check the CNAME, verify DNS again, or contact support. |

Turning tracking off (both `open_tracking` and `click_tracking` set to `false`) or deleting the domain releases the tracking hostname's certificate. You can remove the `ps` CNAME afterwards.

The status is re-checked when you verify the domain (`POST /domains/{id}` with `{"action":"verify"}`) and when you read it with `GET /domains/{id}`. Emails sent while tracking is `pending` are not tracked retroactively.

If delivery-side provisioning fails, settings are still saved but `tracking_error` or `tls_error` may be returned on `PATCH` with a customer-facing message (not raw infrastructure errors).

---

## SDK

```ts
import { Groundmail } from 'groundmail'

const client = new Groundmail(process.env.GROUNDMAIL_API_KEY!)

await client.domains.create({ name: 'example.com' })
await client.domains.apply('example.com')
await client.domains.apply('example.com', { provider: 'vercel' })
await client.domains.apply('example.com', {
  provider: 'godaddy',
  credentials: { apiToken: process.env.GODADDY_PAT! },
})
await client.domains.verify('example.com')

const detail = await client.domains.get('example.com')
const updated = await client.domains.update('example.com', {
  open_tracking: true,
  tls_mode: 'enforced',
})
```

---

## CLI

```bash
groundmail domains add example.com
groundmail domains apply example.com --provider cloudflare
groundmail domains apply example.com --provider vercel
groundmail domains apply example.com --provider netlify        # or digitalocean, dnsimple
GODADDY_PAT=... groundmail domains apply example.com --provider godaddy
groundmail domains verify example.com
```

---

## Delete a domain

`DELETE /domains/{id}`

Removes the domain from your account and revokes sending authorization for that hostname.

```bash
groundmail domains delete example.com
```

If upstream teardown fails, the domain is kept and the API returns **502**.

---

## Common errors

| Status | Meaning |
|--------|---------|
| 400 | invalid domain, DNS not ready, missing provider credentials |
| 401 | missing or invalid auth |
| 403 | domain limit reached, or `tenant` set on an account without tenants (`tenants_not_enabled`) |
| 404 | domain not found, or `tenant` names no tenant of this account |
| 409 | domain already exists or is already claimed |
| 502 | Domain registration, teardown, or DNS provider API failed |

Full contract: [`openapi/groundmail.yaml`](https://docs.groundmail.dev/openapi.yaml)
