# Custom Domain Setup

## Why use a custom domain

By default, sandbox inboxes use the `mailbot.id` domain. Custom domains let you send from your own domain (e.g., `support@yourcompany.com`), which improves deliverability, builds recipient trust, and keeps your brand consistent.

Custom domains are available on the Builder plan and above.

## Add your domain

Domains are managed through the API or an SDK that exposes domain operations. The current MCP tool set does not include domain management. The dashboard covers plan, usage and API keys
only, so there is no Domains screen to open.

```bash
curl -X POST https://getmail.bot/v1/domains \
  -H "Authorization: Bearer mb_xxx" \
  -H "Content-Type: application/json" \
  -d '{"domain": "yourcompany.com"}'
```

The response carries a `dns_records` array with the three records to publish, one each named `SPF`, `DKIM` and
`DMARC`. `GET /v1/domains/:id` returns the same array again at any time.

## Configure DNS records

You need to add three TXT records to your domain's DNS. These records authenticate your emails and protect your domain from spoofing.

### SPF record

Tells receiving mail servers that mailbot is authorized to send email on behalf of your domain.

| Field | Value |
|-------|-------|
| Type | TXT |
| Host | `yourcompany.com` (or `@`) |
| Value | Copy the `SPF` entry from `dns_records` in the API response |

### DKIM record

Adds a cryptographic signature to every email, proving it was not altered in transit.

| Field | Value |
|-------|-------|
| Type | TXT |
| Host | `default._domainkey.yourcompany.com` |
| Value | `v=DKIM1; k=rsa; p=...` — copy the `DKIM` entry from `dns_records` |

### DMARC record

Defines how receiving servers should handle emails that fail SPF or DKIM checks.

| Field | Value |
|-------|-------|
| Type | TXT |
| Host | `_dmarc.yourcompany.com` |
| Value | Copy the `DMARC` entry from `dns_records` |

Note: use the exact values from the `dns_records` array that `POST /v1/domains` returns, and that `GET /v1/domains/:id` returns again at any time. DKIM is generated per domain, so it is never the same for two domains.

## DNS provider instructions

### Cloudflare

1. Log in to your Cloudflare dashboard
2. Select your domain
3. Go to DNS > Records
4. Click "Add record" for each of the three records above
5. Set Type to TXT, enter the Name (Host) and Content (Value)
6. Save each record. TXT records do not have a proxy setting.

### Namecheap

1. Log in to Namecheap and go to Domain List
2. Click "Manage" next to your domain
3. Go to Advanced DNS
4. Click "Add New Record" for each TXT record
5. Set Type to TXT Record, Host, and Value as shown above
6. Save all changes

### GoDaddy

1. Log in to GoDaddy and go to My Products
2. Click DNS next to your domain
3. Click "Add" under Records
4. Set Type to TXT, Name, and Value for each record
5. Set TTL to 1 hour
6. Save

### Route53

1. Open the Route53 console in AWS
2. Select your hosted zone
3. Click "Create record" for each TXT record
4. Set Record type to TXT
5. Enter the Record name and Value
6. Use the default TTL (300 seconds)
7. Click "Create records"

### Other providers

Add TXT records using the `type`, `host` and `value` fields from the `dns_records` array. Most DNS providers have similar interfaces. If you are unsure, check your provider's documentation for "adding TXT records."

## Verify your domain

After publishing all three records, ask mailbot to check them:

```bash
curl -X POST https://getmail.bot/v1/domains/{domain_id}/verify \
  -H "Authorization: Bearer mb_xxx"
```

The response reports each record separately as `spf_verified`, `dkim_verified` and `dmarc_verified`, plus the
overall `status`, a `last_check_at` timestamp and a `next_step` sentence. A record that has not been checked
yet reads as not verified rather than as a pass.

DNS propagation can take up to 48 hours, but usually completes within 15 minutes. If verification fails, double check that you published the exact values from `dns_records` and that there are no trailing spaces.

## Start sending from your domain

Once the domain is verified, create an inbox on it. There is no endpoint that moves an existing inbox to a
different domain, so make a new inbox and send from that one:

```bash
curl -X POST https://getmail.bot/v1/inboxes \
  -H "Authorization: Bearer mb_xxx" \
  -H "Content-Type: application/json" \
  -d '{"username": "support", "domain": "yourcompany.com"}'
```

Use the `address` field from the response as the sending address. Emails from this inbox go out on your own
domain.
