---
title: "Disconnect a mailbox safely"
url: "https://coldagentai.com/docs/guides/disconnect-a-mailbox.md"
canonical_url: "https://coldagentai.com/docs/guides/disconnect-a-mailbox"
last_updated: "2026-11-05"
type: "how-to"
summary: "Pause or re-route the campaigns that use a mailbox, delete it with one call, confirm it is gone, and know what stays untouched."
related: ["https://coldagentai.com/docs/api/mailboxes.md", "https://coldagentai.com/docs/api/campaigns.md", "https://coldagentai.com/docs/errors.md"]
install: "claude mcp add --transport http coldagentai-free https://coldagentai.com/api/mcp"
---

# Disconnect a mailbox safely

> **For AI agents:** the complete index of ColdAgentAI pages is [llms.txt](https://coldagentai.com/llms.txt). Every page is also served as markdown at its URL plus .md.

Pause or re-route the campaigns that use a mailbox, delete it with one call, confirm it is gone, and know what stays untouched.

Remove a mailbox and its stored credentials, pause the campaigns that use it first, and confirm it is gone.

## What you need

- A key with write scope. Disconnecting changes state, so a read key gets `403 forbidden`. See [Authentication](https://coldagentai.com/docs/authentication.md).
- The mailbox id from `GET /v1/mailboxes`.

> Disconnecting cannot be undone. The stored credentials are deleted, and the mailbox has to be connected again from the start to be used again.

## Find the campaigns that use it

Each campaign lists the mailboxes it rotates across in `mailbox_ids`. `GET /v1/campaigns` returns them a page at a time, so page through and keep the campaigns whose `mailbox_ids` contain your mailbox id.

Node:

```
const base = 'https://api.coldagentai.com';
const headers = { Authorization: `Bearer ${process.env.COLDAGENTAI_API_KEY}`, 'Content-Type': 'application/json' };

async function call(method, path, body) {
  const res = await fetch(base + path, { method, headers, body: body === undefined ? undefined : JSON.stringify(body) });
  const json = await res.json();
  if (!res.ok) throw new Error(`${json.error.code}: ${json.error.fix}`);
  return json;
}

const mailboxId = process.env.MAILBOX_ID;
const using = [];
let cursor;
do {
  const query = new URLSearchParams({ limit: '200', ...(cursor ? { cursor } : {}) });
  const page = await call('GET', `/v1/campaigns?${query}`);
  using.push(...page.data.filter((c) => c.mailbox_ids.includes(mailboxId)));
  cursor = page.next_cursor ?? undefined;
} while (cursor);
console.log(using.map((c) => [c.id, c.name, c.status]));
```

## Pause or re-route those campaigns

Deleting the mailbox drops it from every campaign rotation. To keep control of what sends, deal with each active campaign first. There are two ways.

- `POST /v1/campaigns/{id}/pause` stops further sends from the campaign at the next send cycle. Leads keep their place in the sequence. Pausing a paused campaign succeeds and changes nothing; a campaign that has not started or is completed cannot be paused.
- `PATCH /v1/campaigns/{id}` with `mailbox_ids` replaces the whole rotation set, so send the full list of mailboxes you want to keep. It takes effect on the next send cycle, also for an active campaign.

cURL:

```
# Pause one campaign
curl -X POST https://api.coldagentai.com/v1/campaigns/$CAMPAIGN_ID/pause \
  -H "Authorization: Bearer $COLDAGENTAI_API_KEY"

# Or give it a different set of mailboxes
curl -X PATCH https://api.coldagentai.com/v1/campaigns/$CAMPAIGN_ID \
  -H "Authorization: Bearer $COLDAGENTAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "mailbox_ids": ["mbx_keep_1", "mbx_keep_2"] }'
```

Node:

```
const base = 'https://api.coldagentai.com';
const headers = { Authorization: `Bearer ${process.env.COLDAGENTAI_API_KEY}`, 'Content-Type': 'application/json' };

async function call(method, path, body) {
  const res = await fetch(base + path, { method, headers, body: body === undefined ? undefined : JSON.stringify(body) });
  const json = await res.json();
  if (!res.ok) throw new Error(`${json.error.code}: ${json.error.fix}`);
  return json;
}

for (const campaign of using) {
  if (campaign.status === 'active') await call('POST', `/v1/campaigns/${campaign.id}/pause`);
}
```

Starting a campaign again is refused until it has at least one connected mailbox, so a paused campaign whose only mailbox was removed needs a new mailbox in `mailbox_ids` before `POST /v1/campaigns/{id}/start` works.

## Disconnect the mailbox

`DELETE /v1/mailboxes/{id}` removes the mailbox and its stored credentials and drops it from campaign rotations. It takes no body. The response is the id and `deleted: true`.

cURL:

```
curl -X DELETE https://api.coldagentai.com/v1/mailboxes/$MAILBOX_ID \
  -H "Authorization: Bearer $COLDAGENTAI_API_KEY"
```

Node:

```
const base = 'https://api.coldagentai.com';
const headers = { Authorization: `Bearer ${process.env.COLDAGENTAI_API_KEY}`, 'Content-Type': 'application/json' };

async function call(method, path, body) {
  const res = await fetch(base + path, { method, headers, body: body === undefined ? undefined : JSON.stringify(body) });
  const json = await res.json();
  if (!res.ok) throw new Error(`${json.error.code}: ${json.error.fix}`);
  return json;
}

const removed = await call('DELETE', `/v1/mailboxes/${process.env.MAILBOX_ID}`);
console.log(removed);
```

## Confirm it is gone

- `GET /v1/mailboxes/{id}` now answers 404 with [`unknown_product`](https://coldagentai.com/docs/errors.md#unknown_product).
- `GET /v1/mailboxes` no longer lists it.
- Each campaign you looked at earlier no longer has the id in `mailbox_ids`.

Node:

```
const base = 'https://api.coldagentai.com';
const headers = { Authorization: `Bearer ${process.env.COLDAGENTAI_API_KEY}`, 'Content-Type': 'application/json' };

async function call(method, path, body) {
  const res = await fetch(base + path, { method, headers, body: body === undefined ? undefined : JSON.stringify(body) });
  const json = await res.json();
  if (!res.ok) throw new Error(`${json.error.code}: ${json.error.fix}`);
  return json;
}

const res = await fetch(`${base}/v1/mailboxes/${process.env.MAILBOX_ID}`, { headers });
console.log(res.status); // 404 once the mailbox is gone
```

## What disconnecting does not do

- It does not contact the mail provider. The route deletes what ColdAgentAI stores. To withdraw the access you granted, remove it in the settings of the Google, Microsoft or other mail account itself.
- It does not pause campaigns for you, and it does not delete campaigns, sequences or leads.
- It does not delete mail already sent or received, and it does not touch the domain or its DNS records.
- It does not give the mailbox back later. Connect it again with `POST /v1/mailboxes` for IMAP and SMTP, or `POST /v1/mailboxes/gmail/connect` then `POST /v1/mailboxes/gmail/complete` (`microsoft` in place of `gmail` for Microsoft 365) for the OAuth flows.

## What can go wrong

| Code | Cause | Fix |
| --- | --- | --- |
| [`unknown_product`](https://coldagentai.com/docs/errors.md#unknown_product) | The mailbox id is not in your account, or it was already deleted. | List mailboxes with `GET /v1/mailboxes`. |
| [`forbidden`](https://coldagentai.com/docs/errors.md#forbidden) | The key has read scope. | Use a write key. |
| [`invalid_input`](https://coldagentai.com/docs/errors.md#invalid_input) | You tried to pause a campaign that has not started or is completed. | Skip it: only an active campaign needs pausing. |
| [`rate_limited`](https://coldagentai.com/docs/errors.md#rate_limited) | Too many requests for this key. | Wait `Retry-After` seconds. |

## Related

- [Mailboxes API reference](https://coldagentai.com/docs/api/mailboxes.md)
- [Campaigns API reference](https://coldagentai.com/docs/api/campaigns.md)
- [API errors](https://coldagentai.com/docs/errors.md)
