# Verify

Check one address, or up to 100 in one call. Each address costs one credit; `unknown` results are refunded automatically. Results come from the 30-day result cache when possible (still one credit).

## One address

`POST /v1/verify` with `{"email": "...", "wait": 25}`. `wait` (0–25 seconds, default 25) is how long to hold the connection for the SMTP probe. If the probe has not finished by then you get **202** with `state: "pending"`; poll `GET /v1/verify/{id}` until `state` is `done`.

Send an `Idempotency-Key` header (1–200 characters) to make retries free: the same key returns the same request instead of charging again.

```bash
curl https://api.mails.fit/v1/verify \
  -H "Authorization: Bearer $MAILSFIT_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: signup-42" \
  -d '{"email": "jane@example.com", "wait": 10}'
```

```javascript
async function verify(email) {
  const headers = { Authorization: `Bearer ${process.env.MAILSFIT_KEY}` };
  let res = await fetch("https://api.mails.fit/v1/verify", {
    method: "POST",
    headers: { ...headers, "Content-Type": "application/json" },
    body: JSON.stringify({ email, wait: 10 }),
  });
  let v = await res.json();
  while (v.state === "pending") {
    await new Promise((r) => setTimeout(r, 2000));
    v = await (await fetch(`https://api.mails.fit/v1/verify/${v.id}`, { headers })).json();
  }
  return v;
}
```

```python
import os, time, requests

API = "https://api.mails.fit/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['MAILSFIT_KEY']}"}

def verify(email):
    v = requests.post(f"{API}/verify", headers=HEADERS, json={"email": email, "wait": 10}, timeout=30).json()
    while v.get("state") == "pending":
        time.sleep(2)
        v = requests.get(f"{API}/verify/{v['id']}", headers=HEADERS, timeout=30).json()
    return v
```

```go
func verify(email string) (map[string]any, error) {
	payload, _ := json.Marshal(map[string]any{"email": email, "wait": 10})
	req, _ := http.NewRequest("POST", "https://api.mails.fit/v1/verify", bytes.NewReader(payload))
	req.Header.Set("Authorization", "Bearer "+os.Getenv("MAILSFIT_KEY"))
	req.Header.Set("Content-Type", "application/json")
	res, err := (&http.Client{Timeout: 30 * time.Second}).Do(req)
	if err != nil {
		return nil, err
	}
	defer res.Body.Close()
	var v map[string]any
	err = json.NewDecoder(res.Body).Decode(&v)
	return v, err // poll GET /v1/verify/{id} while v["state"] == "pending"
}
```

```php
function verify(string $email): array {
    $ch = curl_init("https://api.mails.fit/v1/verify");
    curl_setopt_array($ch, [
        CURLOPT_POST => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTPHEADER => [
            "Authorization: Bearer " . getenv("MAILSFIT_KEY"),
            "Content-Type: application/json",
        ],
        CURLOPT_POSTFIELDS => json_encode(["email" => $email, "wait" => 10]),
    ]);
    return json_decode(curl_exec($ch), true); // poll GET /v1/verify/{id} while state is pending
}
```

```rust
async fn verify(client: &reqwest::Client, key: &str, email: &str) -> reqwest::Result<serde_json::Value> {
    let mut v: serde_json::Value = client
        .post("https://api.mails.fit/v1/verify")
        .bearer_auth(key)
        .json(&serde_json::json!({ "email": email, "wait": 10 }))
        .send().await?.json().await?;
    while v["state"] == "pending" {
        tokio::time::sleep(std::time::Duration::from_secs(2)).await;
        let url = format!("https://api.mails.fit/v1/verify/{}", v["id"]);
        v = client.get(url).bearer_auth(key).send().await?.json().await?;
    }
    Ok(v)
}
```

## Batch

`POST /v1/verify/batch` with `{"emails": [...], "wait": 25}` verifies 1 to 100 addresses through the same pipeline, one credit each, and waits for them together. It always answers **200** with one item per address, in order:

- a verification (same fields as above; `state` may be `pending`, poll its `id`), or
- `{"email": "...", "error": {"code": "...", "message": "..."}}` when that address was not charged (for example an empty string).

The whole batch is refused with 402 `insufficient_credits` when your balance cannot cover it. With `Idempotency-Key: K`, item `i` uses the key `K:i`, so a retry charges only addresses not sent before (`K` at most 190 characters). For more than 100 addresses, upload a [list](/docs/lists).

```bash
curl https://api.mails.fit/v1/verify/batch \
  -H "Authorization: Bearer $MAILSFIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"emails": ["jane@example.com", "info@example.org"], "wait": 20}'
```

```javascript
const res = await fetch("https://api.mails.fit/v1/verify/batch", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MAILSFIT_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ emails: ["jane@example.com", "info@example.org"], wait: 20 }),
});
const { results, pending } = await res.json();
for (const r of results) console.log(r.email, r.status ?? r.error?.code);
```

```python
res = requests.post(
    "https://api.mails.fit/v1/verify/batch",
    headers={"Authorization": f"Bearer {os.environ['MAILSFIT_KEY']}"},
    json={"emails": ["jane@example.com", "info@example.org"], "wait": 20},
    timeout=60,
)
for r in res.json()["results"]:
    print(r["email"], r.get("status") or r["error"]["code"])
```

```go
payload, _ := json.Marshal(map[string]any{
	"emails": []string{"jane@example.com", "info@example.org"},
	"wait":   20,
})
req, _ := http.NewRequest("POST", "https://api.mails.fit/v1/verify/batch", bytes.NewReader(payload))
req.Header.Set("Authorization", "Bearer "+os.Getenv("MAILSFIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, err := (&http.Client{Timeout: 60 * time.Second}).Do(req)
if err != nil {
	log.Fatal(err)
}
defer res.Body.Close()
var out struct {
	Results []map[string]any `json:"results"`
	Pending int              `json:"pending"`
}
json.NewDecoder(res.Body).Decode(&out)
```

```php
$ch = curl_init("https://api.mails.fit/v1/verify/batch");
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 60,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("MAILSFIT_KEY"),
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => json_encode(["emails" => ["jane@example.com", "info@example.org"], "wait" => 20]),
]);
foreach (json_decode(curl_exec($ch), true)["results"] as $r) {
    echo $r["email"], " ", $r["status"] ?? $r["error"]["code"], "\n";
}
```

```rust
let out: serde_json::Value = reqwest::Client::new()
    .post("https://api.mails.fit/v1/verify/batch")
    .bearer_auth(std::env::var("MAILSFIT_KEY")?)
    .json(&serde_json::json!({ "emails": ["jane@example.com", "info@example.org"], "wait": 20 }))
    .send()
    .await?
    .json()
    .await?;
for r in out["results"].as_array().into_iter().flatten() {
    println!("{} {}", r["email"], r.get("status").unwrap_or(&r["error"]["code"]));
}
```

```json
{
  "results": [
    { "id": 1843, "state": "done", "email": "jane@example.com", "status": "deliverable", "reason": "accepted", "score": 95, "...": "..." },
    { "id": 1844, "state": "pending" }
  ],
  "pending": 1
}
```

## Response fields

| Field | Type | Meaning |
|---|---|---|
| `id` | integer | Request id; poll `GET /v1/verify/{id}` |
| `state` | `done` or `pending` | `pending` comes with HTTP 202 |
| `email` | string | The address as checked |
| `status` | string | `deliverable`, `risky`, `undeliverable` or `unknown` |
| `reason` | string | Why; see the table below |
| `score` | 0–100 | 80–100 send, 50–79 care, 0–49 drop |
| `suggestion` / `did_you_mean` | string or null | Typo fix, for example `jane@gmail.com` for `jane@gmial.com` (same value) |
| `disposable` | boolean | Throwaway inbox provider |
| `free` | boolean | Free mailbox provider (gmail.com, outlook.com, ...) |
| `role` | boolean | Role address (info@, sales@, ...) |
| `catch_all` | boolean or null | The domain accepts any address; `null` when not tested |
| `mx_found` | boolean or null | The domain publishes MX hosts; `null` when DNS was not read |
| `mx_group` / `smtp_provider` | string | `google`, `microsoft`, `yahoo`, `mimecast` or `other` (same value) |
| `mx_host` | string or null | The MX host that answered |
| `smtp_code` | integer or null | SMTP reply code to RCPT TO |
| `spam_trap_risk` | array | `typo_domain`, `listed_domain`, `trap_local_part`; omitted when empty. A risk signal, never a verdict |

## Reasons

Each `reason` maps to exactly one `status`.

| Reason | Status | Meaning |
|---|---|---|
| `accepted` | deliverable | The mailbox server accepted the recipient |
| `invalid_syntax` | undeliverable | Not a valid address |
| `no_mx` | undeliverable | The domain has no mail server |
| `user_unknown` | undeliverable | The server says the mailbox does not exist |
| `mx_not_public` | undeliverable | Every MX address is private or unreachable from the internet |
| `catch_all` | risky | The domain accepts any address, so this one cannot be confirmed |
| `role` | risky | Accepted, but a shared role mailbox |
| `disposable` | risky | Throwaway inbox provider |
| `mailbox_full` | risky | The mailbox exists but is full |
| `provider_unverifiable` | risky | Microsoft 365 or Yahoo accepted without a clear answer for a random control address |
| `greylisted` | unknown | Temporary deferral; try later |
| `blocked` | unknown | The server refused our probe, not the mailbox |
| `timeout` | unknown | No answer in time |
| `dns_error` | unknown | DNS lookup failed temporarily |
| `inconclusive` | unknown | A refusal that proves nothing about the mailbox |
| `suppressed` | unknown | The domain or address [opted out](/optout); nothing was checked |
