# Inboxes for every user of your platform

> Give each of your users their own inboxes, under your product. Each user gets a pod: their inboxes, mail, domains and webhooks, apart from everyone else’s. Their mail goes out from their own domain. One account, one bill.

Source: https://zurchin.com/docs/platforms

## One pod per user

| Piece | What it gives your user |
| --- | --- |
| [Pod](https://zurchin.com/docs/api-keys.md#pods) | A space of their own: inboxes, mail, domains, agents and webhook endpoints. |
| A key of the pod | Reaches that pod and nothing else. Give it to their agent. |
| Their domain | Inboxes such as `sales@theirco.com`, signed as their domain. |
| A webhook of the pod | Hears that pod’s mail only. |

Pods are free, as many as you need. Billing, the team, sending limits and reputation stay with your account, across every pod.

## 1. Make a pod for the user

With an `admin` key of the whole account. Name it after the user: up to 80 characters, unique in the account.

curl:

```bash
curl https://zurchin.com/v1/pods \
  -H "Authorization: Bearer $ZURCHIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "Northwind"}'
```

TypeScript:

```ts
import { Zurchin } from '@zurchin/sdk';

const zurchin = new Zurchin({ apiKey: process.env.ZURCHIN_API_KEY! });
const pod = await zurchin.pods.create('Northwind');
```

Python:

```python
import os
from zurchin import Zurchin

zurchin = Zurchin(api_key=os.environ["ZURCHIN_API_KEY"])
pod = zurchin.pods.create("Northwind")
```

## 2. Make a key of that pod

Pass `pod_id` to `POST /v1/keys`. The key is in the answer once: store it with the user’s record.

curl:

```bash
curl https://zurchin.com/v1/keys \
  -H "Authorization: Bearer $ZURCHIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "Northwind agent", "access": "admin", "pod_id": "<the pod’s id>"}'
```

TypeScript:

```ts
const { key } = await zurchin.keys.create({
  name: 'Northwind agent',
  access: 'admin',
  podId: pod.id,
});
```

Python:

```python
made = zurchin.keys.create("Northwind agent", access="admin", pod_id=pod["id"])
key = made["key"]
```

- It makes, lists and removes inboxes in its pod, and reads and sends their mail.
- A webhook endpoint it adds hears its pod only.
- It cannot reach another pod, make pods or make keys. It gets `403` for whole-account calls: domains, rules and the do-not-send list.
- `send` is enough for an agent that only reads and writes mail; `admin` also makes inboxes.

## 3. Give the user inboxes

With the pod’s key, an inbox lands in the pod. Without a domain it is on `zurchin.email`: live at once, no DNS.

curl:

```bash
curl https://zurchin.com/v1/email/inboxes \
  -H "Authorization: Bearer $POD_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "northwind-sales", "display_name": "Northwind Sales"}'
```

TypeScript:

```ts
const northwind = new Zurchin({ apiKey: podKey });
const inbox = await northwind.inboxes.create({
  name: 'northwind-sales',
  displayName: 'Northwind Sales',
});
```

Python:

```python
northwind = Zurchin(api_key=pod_key)
inbox = northwind.inboxes.create("northwind-sales", display_name="Northwind Sales")
```

An account adds at most 50 inboxes a day on `zurchin.email`, across all pods. On a user’s own domain there is no daily limit.

## 4. Put the user’s own domain on

White-label: the user’s mail goes out from their domain, signed with DKIM as their domain, and replies come back to their pod.

1. **Add the domain** in the user’s pod: `POST /v1/domains` with `{"domain": "theirco.com"}` and the pod’s key (or `pod_id` with a key of the whole account). It answers the one TXT record that proves it: `_pidgeon.<domain>` holding `pidgeon-verify=<token>`. Once it is set, `POST /v1/domains/{id}/verify`. Every field: [Domains from the API](https://zurchin.com/docs/email.md#domains-api).
2. **Turn mail on** with the pod’s key: `POST /v1/email/domains/{id}/mail`. It answers the MX, SPF and DKIM records to set; `GET /v1/domains/{id}` answers them too, with the TXT record.
3. **Set the records** at the domain’s DNS host, then **check**: `POST /v1/email/domains/{id}/check`. Inboxes there send once `status` is `verified`.
4. **Make inboxes there** with the pod’s key: `{"name": "sales", "domain": "theirco.com"}`. On their own domain every name is theirs, `support@` included.

The MX moves all of the domain’s mail to Zurchin. When the user’s mail lives elsewhere, use a subdomain such as `agents.theirco.com`. Every record and field: [Your own domain](https://zurchin.com/docs/email.md#domains).

### Records set for the user

Where the domain’s DNS host speaks Domain Connect and has switched Zurchin’s template on, the dashboard offers to set two records on the host’s own page: the `_pidgeon` TXT that proves the domain, and the `pgn2._domainkey` CNAME that lets Zurchin sign an agent’s `Agent-of` declaration as the domain. The MX, SPF and DKIM records are set by hand. Zurchin holds no DNS credential.

When the user leaves, `DELETE /v1/domains/{id}` takes the domain back once no inbox is left at it, turning its mail off first.

## 5. Hear the user’s mail

Add a webhook endpoint with the pod’s key, or pass `pod_id` with a key of the whole account. It hears that pod’s events only: `message.received`, bounces, held mail. Or have the agent wait for mail with `GET /v1/email/inboxes/{id}/messages/await`.

```bash
curl https://zurchin.com/v1/webhooks \
  -H "Authorization: Bearer $POD_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://app.example/hooks/pidgeon", "events": ["message.received"]}'
```

Every event and its signature: [Webhooks](https://zurchin.com/docs/webhooks.md).

## Rename, move, remove

- Rename a pod: `PATCH /v1/pods/{id}`. Its id and everything in it stay.
- Move an inbox, a domain, an agent or a webhook endpoint into another pod: `POST /v1/pods/{id}/move`. Keys of the old pod stop reaching it.
- Remove a user: `DELETE /v1/pods/{id}`. A pod with inboxes, domains, agents or webhook endpoints in it answers `409` until they are removed or moved.

**Settings → Pods** lists them. Once there are two, a switcher at the top shows one pod or all.
