# CleanMail - for AI agents

> CleanMail answers one question: **will this address receive mail?**
> It checks the domain's mail exchangers, talks to the mail server, and
> scores the risk - disposable providers, role accounts, catch-all
> servers and greylists - so a signup form can reject the addresses
> that will bounce before anything is sent.

This file is the working manual. It says what to call, in what order,
and what not to do. The full reference is at https://cleanmail.dev/llms-full.txt.

## Start here

- Base URL: `https://cleanmail.dev`
- Authentication: `X-API-Key: <your key>` in the header
- Content type: `application/json`
- The key is on the account page: `https://cleanmail.dev/app.html`

```bash
export CLEANMAIL_API_KEY="your_api_key_here"

curl -X POST https://cleanmail.dev/api/verify \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $CLEANMAIL_API_KEY" \
  -d '{"email":"user@example.com"}'
```

With the typed SDK (no runtime dependencies):

```bash
npm install cleanmail-sdk
```

```ts
import { CleanMailClient } from 'cleanmail-sdk';

const cleanmail = new CleanMailClient({ apiKey: process.env.CLEANMAIL_API_KEY! });
const result = await cleanmail.verifyEmail({ email: 'user@example.com' });

if (result.deliverable && result.riskLevel !== 'high') {
  // accept the signup
}
```

## Which endpoint to call

| You want | Call | Note |
| --- | --- | --- |
| One address, fastest answer | `POST /api/verify/quick` | the same check with a trimmed response - use it to pre-filter a signup form |
| One address, the full answer | `POST /api/verify` | the reason, the risk score, the mail exchanger and the security records |
| Up to 500 addresses in one call | `POST /api/verify/batch` | one request, up to 500 addresses |
| A CSV of addresses | `POST /api/batch/upload` | up to 5000 rows; the job is followed and downloaded as a CSV |
| No API key (a demo, not production) | `POST /api/demo/verify` | 10 requests a minute, 100 a day and 15 different email domains a day per IP |

## The rules that are not obvious

These are the ones that make an integration correct. They are also
the ones a language model gets wrong when it has only seen the schema.

1. **`deliverable: true` means the mail server accepted the recipient
   during the SMTP check.** It does not mean a human reads the mail, and
   a catch-all server answers true for every address it is given. For a
   catch-all domain, treat `isCatchall: true` as "nobody can tell".
2. **`reason` is the verdict, and it has 10 values:** `accepted`, `blocked`, `busy`, `disposable`, `error`, `invalid`, `risky`, `spam_trap`, `unknown`, `valid`.
3. **`accepted` is not `valid`.** `valid` is a fact about the mailbox.
   `accepted` means the mail server took the recipient but would not
   tell us whether the mailbox exists - a catch-all domain, or a
   provider such as Yahoo or AOL that answers `250` for every
   recipient on purpose. `existenceConfirmed: false` says the same
   thing in a field. Do not record either as "the mailbox exists".
4. **You only pay for answers.** A check that timed out or came back
   `busy` is not charged: the response carries `X-Cost: 0`. Retry it
   after the `Retry-After` header instead of recording it as invalid.
5. **`busy` is not `invalid`.** `busy` means the mail server asked us to
   come back later (421/450/451/452) and nobody answered about the
   mailbox yet.
6. **`disposable` is final and no mail server is contacted.** The
   domain is on the disposable list (a subdomain of one counts), so
   the answer is `reason: "disposable"` with no MX lookup and no
   SMTP conversation.
7. **Every check carries the headers you need:** `X-RateLimit-Limit`,
   `X-RateLimit-Remaining` and `X-Cost`.
8. **The daily allowance is the limit**, not the per-second rate. A
   plan may aim at as many different mail servers as it has
   verifications a day.
9. **The per-second limits are per worker process.** The service runs
   4 workers, so a burst can briefly be 4 times the per-minute figure.
10. **One verification is one unit of the daily allowance.** Batch
    uploads do not count against it.
11. **Never point a bulk run at one mail server.** Spread the addresses
    over many domains; a concentrated burst gets the domain blocked.

## Limits

| Plan | Verifications a day | Price | Single requests | Burst | Batch requests | Batch burst |
| --- | ---: | ---: | ---: | ---: | ---: | ---: |
| free | 50 | $0 | 1 | 3 | 5 | 20 |
| starter | 300 | $9 | 2 | 5 | 10 | 50 |
| pro | 1,500 | $39 | 3 | 10 | 25 | 100 |
| business | 5,000 | $99 | 20 | 50 | 50 | 200 |
| enterprise | 20,000 | $199 | 20 | 50 | 50 | 200 |

- The inline batch limit is 500 addresses; a CSV upload takes 5000 rows.
- The demo endpoint allows 10 requests a minute, 100 a day and 15
  different email domains a day per IP address; an IPv6 address is
  counted per /64.

## Every endpoint

The complete list, straight out of the published specification:

| Method | Path | Needs |
| --- | --- | --- |
| `POST` | `/api/batch/cancel/{jobId}` | API key |
| `GET` | `/api/batch/download/{jobId}` | API key |
| `GET` | `/api/batch/history` | API key |
| `DELETE` | `/api/batch/jobs` | API key |
| `DELETE` | `/api/batch/jobs/{jobId}` | API key |
| `GET` | `/api/batch/status/{jobId}` | API key |
| `POST` | `/api/batch/upload` | API key |
| `GET` | `/api/billing/portal` | session token |
| `GET` | `/api/billing/subscription` | session token |
| `POST` | `/api/billing/webhook` | none (public) |
| `POST` | `/api/demo/verify` | none (public) |
| `GET` | `/api/features` | none (public) |
| `GET` | `/api/key/{key}` | none (public) |
| `GET` | `/api/usage` | API key |
| `POST` | `/api/verify` | API key |
| `POST` | `/api/verify/batch` | API key |
| `POST` | `/api/verify/quick` | API key |
| `GET` | `/api/webhooks` | API key |
| `POST` | `/api/webhooks/register` | API key |
| `DELETE` | `/api/webhooks/{id}` | API key |
| `DELETE` | `/auth/account` | session token |
| `GET` | `/auth/api-key` | session token |
| `POST` | `/auth/change-password` | session token |
| `GET` | `/auth/export` | session token |
| `POST` | `/auth/forgot-password` | none (public) |
| `POST` | `/auth/login` | none (public) |
| `GET` | `/auth/me` | session token |
| `PUT` | `/auth/profile` | session token |
| `POST` | `/auth/profile/confirm` | session token |
| `POST` | `/auth/resend-code` | none (public) |
| `POST` | `/auth/resend-key` | session token |
| `POST` | `/auth/reset-password` | none (public) |
| `POST` | `/auth/rotate-key` | session token |
| `POST` | `/auth/signup` | none (public) |
| `POST` | `/auth/verify` | none (public) |
| `GET` | `/health` | none (public) |
| `POST` | `/mcp` | API key |
| `GET` | `/mcp` | API key |

The `/auth/*` routes belong to the signed-in account and take the
session token from `POST /auth/login` in the `X-Session-Token` header.
An API key will not work on them.

## Call it as a tool (MCP)

The service speaks the Model Context Protocol at `https://cleanmail.dev/mcp`. An agent
that connects there is offered these tools - the same work, without
the agent having to write the request itself:

| Tool | What it does |
| --- | --- |
| `verify_email` | Check whether one email address is deliverable. Answers with deliverable (true when the mail server accepted the recipient), the reason (valid, invalid, accepted, disposable, spam_trap, blocked, risky, busy, unknown or error), existenceConfirmed (true when the answer settles whether the mailbox exists - false for accepted, busy and unknown), a risk score from 0 to 100, and the domain's mail records (mail exchanger, SPF, DMARC). 'accepted' means the server took the recipient but would not say whether the mailbox exists - a catch-all domain, or a provider such as Yahoo or AOL that accepts every recipient on purpose. One address per call; use check_domain for the domain alone. |
| `check_domain` | Check how a domain handles mail without checking any address: its mail exchangers, its SPF record and whether it is strict, its DMARC policy, and how many days ago the domain was registered. DNS lookups only - no connection to the domain's mail server is opened, and no address is needed or stored. |

The key goes in `X-API-Key` or in `Authorization: Bearer <key>`. A
verification goes through the same path as `POST /api/verify`: the
same rate limit, the same daily allowance and the same accounting, so
an MCP call is not a cheaper way into the service.

```bash
# 1. say hello (once per session)
curl -s -X POST https://cleanmail.dev/mcp \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $CLEANMAIL_API_KEY" \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"my-agent","version":"1.0.0"}}}'

# 2. see the tools
curl -s -X POST https://cleanmail.dev/mcp \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $CLEANMAIL_API_KEY" \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'

# 3. use one
curl -s -X POST https://cleanmail.dev/mcp \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $CLEANMAIL_API_KEY" \
  -d '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"verify_email","arguments":{"email":"user@example.com"}}}'
```

## More

- The machine-readable specification: https://cleanmail.dev/openapi.json
- The full text reference: https://cleanmail.dev/llms-full.txt
- The human guide: https://cleanmail.dev/docs.html
- The SDK and CLI: `cleanmail-sdk` on npm
- A runnable collection: https://cleanmail.dev/postman_collection.json

