# Route inbound email

This recipe turns a domain into a receiving mail system.

## 1. Prepare the domain

Use a domain or subdomain you control. A dedicated subdomain such as `mail.example.com` is easier to reason about than mixing with existing mail.

## 2. Add the receiving domain

In **Dashboard → Inbound email → Receiving domains**, add the domain and verify ownership by publishing the token record shown. Once ownership is confirmed, Bonga shows the MX target.

## 3. Publish MX

Publish the MX record at the domain root:

```dns
mail.example.com. 3600 IN MX 10 mx.bonga.africa.
```

If DNS is connected, Bonga can apply it for you. Wait for propagation; Bonga reads the record independently before marking the domain ready.

## 4. Create rules

Start narrow:

| Address | Match | Action |
| --- | --- | --- |
| `support@mail.example.com` | exact | store |
| `billing@mail.example.com` | exact | store, forward to finance |
| `*@mail.example.com` | catch-all | store |

A catch-all catches everything not matched by a more specific rule. Only one workspace can own an exact address.

## 5. Read captured mail

Captured messages appear in the shared inbox. Each includes authentication results, spam verdict and threading headers. Attachments are private and downloaded only through an authorized route.

## 6. Add a webhook

For automated processing, create a rule with action `webhook` and a workspace endpoint subscribed to `message.received`. Verify the signature before parsing and deduplicate by event ID.

## 7. Test the paths

- Send from an external address to the exact address.
- Send to a random local part to test the catch-all.
- Reply to a captured message and confirm it threads.
- Send an attachment and download it.
- Break the signature on a webhook and confirm your handler refuses it.

## Troubleshooting

| Symptom | Fix |
| --- | --- |
| Domain not ready | Ownership token, MX value, propagation |
| No capture | Rule action, address match, domain status |
| Wrong inbox | Another rule owns the address more specifically |
| Reply not threaded | Reply-To token, `In-Reply-To`, `References` |
| Attachment fails | Retention, authorization, private storage |

## Next

- [Inbound email](/docs/inbound-email)
- [Webhooks](/docs/webhooks)
- [Email](/docs/email)
