---
title: Migrate from AgentMail
description: One command moves your AgentMail inboxes, domains, lists, webhooks and mail history; the BillionSend SDKs and one API key move your code.
---

BillionSend does not copy AgentMail's API, so moving over has two parts: one command moves your account data, and you change the calls in your code to the BillionSend SDK. Both are short.

## 1. Move your account

Create a full-access `bs_` API key under **API keys**, then run on your machine:

```sh
npx @billionsend/cli migrate --from agentmail
```

It asks for your AgentMail API key and your BillionSend key (or reads `AGENTMAIL_API_KEY` and `BILLIONSEND_API_KEY`), reads your AgentMail account, shows a plan, waits for your confirmation, applies it and prints a summary. For the EU region, set `AGENTMAIL_BASE_URL=https://api.agentmail.eu`. Flags, files and CI use are on the [CLI](/docs/cli) page.

- **AgentMail is only read.** The tool never creates, changes or deletes anything there. Your keys stay in memory for the run and are never written to a file. There is no telemetry.
- **Safe to run again.** Domains, inboxes and webhooks are matched by name, address and URL, and a message BillionSend already holds is answered `duplicate` and not stored twice. The tool also remembers what it imported in `.billionsend/agentmail-state.json`, so a repeat run reads only what is new.
- **See the plan first.** `migrate plan --from agentmail` only reads: it exits 0 when there is nothing left to do and 2 when there is. `--only` and `--skip` take `domains`, `inboxes`, `lists`, `webhooks` and `messages`. `--report <file>` writes the report to that path.
- **It writes a report** (`.billionsend/agentmail-report.md`): the old and new address of every inbox, the DNS records to publish, the steps to switch a domain's mail, everything that did not move and why, and the SDK calls to rewrite.

| Resource | What moves |
| --- | --- |
| Domains | Added to BillionSend, with the DNS records to publish in the report. An inbox on a domain waits until the domain is verified: publish the records, then run the command again. It then turns receiving on and creates the inboxes. |
| Inboxes | An inbox on your own domain keeps its address. An inbox on AgentMail's own domain cannot: it gets the same name on your shared inbox address (`name@<team>.billionsend.app`, no DNS), and the report maps old to new. A display name becomes the inbox's from name. A name BillionSend reserves, or one already taken, fails and is listed. Deactivated inboxes are not created. |
| Lists | A receive allow list becomes the inbox's allowlist: mail from anyone else is held for review, not dropped. The organization's send block list becomes manual suppressions for the whole team. Receive block, reply and send allow lists have no equivalent and are listed with their entries. |
| Webhooks | URL, enabled state and inbox filter. Events carry over where BillionSend has the same one (`message.received` is `email.received`, `message.sent`, `delivered`, `bounced`, `complained` and `opened` are the `email.*` events of the same name, `message.rejected` is `email.failed`, `domain.verified` is `domain.updated`); spam, blocked, security and calendar events have none. A signing secret in the `whsec_` format moves with the webhook so your receiver keeps verifying; any other is replaced by a new one, shown once in the terminal and never written to a file. |
| Messages | Every message the inbox received, with its original time, in the threads AgentMail had, with its read state (a message without AgentMail's `unread` label is read), attachments included. They are searchable, readable through the thread routes and over IMAP like any other mail. |

What does not move: mail the inbox sent, drafts, custom labels, signatures, pods, calendars and API keys (create new ones under **API keys**).

### What importing mail does and does not do

Imported mail is history, not new mail. It spends no receiving allowance, is not screened, judged or forwarded, and announces nothing: no `email.received` webhook, no inbox event, nothing on the event stream. Three limits still apply because they are about holding data: a message older than your plan's received-mail retention window (30 days on Free, 90 days on paid plans) is not imported, since BillionSend would remove it at once; a message over 25 MiB is not imported; and the plan's received-mail storage cap stops the import when it is full (the command says so and you can run it again after freeing room or upgrading).

## 2. Switch a domain's mail without losing any

Do this per domain, after step 1 created it. The report has the exact records.

1. A day before, lower the TTL of the domain's MX records to 300 seconds or less.
2. Publish BillionSend's DNS records and wait until the domain shows verified. Run the command again: it turns receiving on and creates the inboxes on the domain.
3. Add BillionSend's MX records beside AgentMail's, at the same priority. Mail then reaches either side, and a sender that gets no answer retries for days.
4. Run the command again after a few minutes, and once more after step 5. Each run imports what AgentMail received in between and stores nothing twice.
5. Remove AgentMail's MX records. Keep the AgentMail account until the last run shows nothing left to import.

## 3. Point your code at BillionSend

Install the SDK (`npm install @billionsend/node` or `pip install billionsend`), set `BILLIONSEND_API_KEY` and replace the calls. The Python and TypeScript SDKs share the names below; Python writes them in snake_case.

| AgentMail | BillionSend |
| --- | --- |
| `inboxes.create(username, domain, display_name)` | `inboxes.create({ username, domain_id, from_name })`; leave `domain_id` out for the shared inbox address |
| `inboxes.get / list / update / delete` | `inboxes.get / list / update / delete` |
| `inboxes.messages.send(inbox_id, to, subject, text)` | `inboxes.send(inbox_id, { to, subject, text })` |
| `inboxes.messages.reply / forward` | `inboxes.threads.emails.reply / forward` |
| `inboxes.messages.list / get` | `inboxes.threads.emails.list / get`, or `emails.receiving.list` with `inbox_id` |
| `inboxes.messages.update` (read, labels) | `inboxes.threads.update` (`read`), `inboxes.threads.labels.add / set / remove` |
| `threads.list`, `inboxes.threads.get / update / delete` | `inboxes.threads.list / get / update / delete` (threads live inside one inbox) |
| `threads.search`, `inboxes.messages.search` | `inboxes.threads.search` |
| `inboxes.drafts.*` | `inboxes.drafts.*` |
| `lists.*`, `inboxes.lists.*` | `inboxes.safety.update` (allowlist), `suppressions.batch.add` |
| `webhooks.create(url, event_types, inbox_ids)` | `webhooks.create({ endpoint, events, inbox_ids })` |
| `domains.create / get / list / delete / verify` | `domains.create / get / list / delete / verify` |
| WebSocket client | `inboxes.events.stream` (server-sent events, resumable with `Last-Event-ID`) |

```ts
import { BillionSend } from "@billionsend/node";

const bs = new BillionSend(); // reads BILLIONSEND_API_KEY

await bs.inboxes.send("support@acme.dev", {
  to: ["ann@customer.example"],
  subject: "Your order shipped",
  text: "It is on its way.",
});

const { data: threads } = await bs.inboxes.threads.list("support@acme.dev");
```

An inbox id can be its address wherever the API takes one. A send the inbox's [send policy](/docs/inboxes) holds becomes a draft a person approves, so reading the answer matters: `inboxes.send` answers the sent email or, with status 202, the held draft. Webhook signatures follow the Standard Webhooks format; see [Webhooks](/docs/concepts/webhooks).
