MailSpecto
API and integrations 4 min read

Email verification API – how to integrate validation into your app

Verifying the address in a sign-up or checkout form stops typos and disposable addresses before they reach your database. We show a secure architecture, a Next.js example, how to map the JSON response to messages for the user, and how to handle errors.

MailSpecto Engineering Team

Mail infrastructure and deliverability

Form onBlur / submit Your backend API key in env MailSpecto API POST /api/v1/verify Decision status + suggestion

1. Architecture: the API key stays on the server

The most common integration mistake is calling the verification API straight from the browser. Anyone can read an API key placed in frontend code and then use up your credits. The correct flow is:

  1. The browser sends the address to your backend (e.g. a Route Handler in Next.js).
  2. The backend, with the key in an environment variable, calls POST /api/v1/verify.
  3. The backend turns the result into a simple decision for the form: accept, block or suggest a correction.

This way the key never leaves the server, and you control who can use verification and how often.

Your endpoint needs protecting too

A public endpoint that verifies any address can be used to check other people's lists at your expense. Rate-limit requests per IP address and session, and add a CAPTCHA to sign-up (e.g. Cloudflare Turnstile).

2. Calling the API

The request takes a single email field, and the response contains the status, a reason code, flags and the details of each check:

curl -X POST https://api.mailspecto.com/api/v1/verify \
  -H "Authorization: Bearer $MAILSPECTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"email": "[email protected]"}'

The most important response fields:

FieldWhat it is for
statusThe main decision: mailbox_exists, catch_all, domain_accepts_mail, risky, invalid, unknown
reason_codeThe specific reason, e.g. possible_typo, disposable_domain, mailbox_not_found
flagsQuick flags: is_disposable, is_role_account, has_typo_suggestion and others
suggested_correctionThe suggested correct address, e.g. [email protected]
mailbox_verifiedWhether the recipient's server answered about this specific mailbox

The full list of fields and codes is in the API documentation.

3. Example: a Next.js Route Handler

The handler below takes the address from the form, asks MailSpecto and returns a simplified decision. The key is in MAILSPECTO_API_KEY, set on the server only.

// app/api/check-email/route.ts
type Verdict = { ok: boolean; message?: string; suggestion?: string };

export async function POST(req: Request) {
  const { email } = await req.json();
  if (typeof email !== "string" || email.length < 3 || email.length > 254) {
    return Response.json({ ok: false, message: "Please enter a valid email address." });
  }

  let res: Response;
  try {
    res = await fetch("https://api.mailspecto.com/api/v1/verify", {
      method: "POST",
      headers: {
        Authorization: `Bearer ${process.env.MAILSPECTO_API_KEY}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ email }),
      signal: AbortSignal.timeout(8000),
    });
  } catch {
    return Response.json({ ok: true }); // timeout or network error: do not block the customer
  }

  if (!res.ok) {
    const code = (await res.json().catch(() => null))?.error?.code;
    console.error("mailspecto verify failed", res.status, code);
    return Response.json({ ok: true }); // 402, 429, 503: accept the address, handle the alert
  }

  return Response.json(toVerdict(await res.json()));
}

function toVerdict(r: any): Verdict {
  if (r.flags?.has_typo_suggestion && r.suggested_correction) {
    return { ok: true, suggestion: r.suggested_correction };
  }
  if (r.status === "invalid") {
    return { ok: false, message: "Mail cannot be delivered to this address." };
  }
  if (r.flags?.is_disposable) {
    return { ok: false, message: "Please use a permanent email address, not a disposable one." };
  }
  return { ok: true };
}

In the form, call this endpoint when the field loses focus (onBlur) and once more on submit:

// part of the form component ("use client")
async function check(email: string) {
  const res = await fetch("/api/check-email", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ email }),
  });
  const verdict = await res.json();
  if (verdict.suggestion) setHint(`Did you mean ${verdict.suggestion}?`);
  else setError(verdict.ok ? null : verdict.message);
}

A few rules for good UX:

  • Do not verify on every keystroke. It wastes credits and gives confusing messages for an unfinished address.
  • Show a typo suggestion as a question with a "Fix it" button, not as an error. The user may be right.
  • Remember the result for an address within the session, so you do not pay twice for the same check.

4. Mapping statuses to decisions

How strictly to treat each status depends on the form. An example setup for account sign-up:

Status / flagAccount sign-upNewsletter sign-up
mailbox_existsAcceptAccept
catch_all, domain_accepts_mailAcceptAccept, confirm with double opt-in
risky + typoSuggest a correctionSuggest a correction
risky + disposableBlockBlock
is_role_account flag (role address)Accept (B2B)Accept
invalidBlock with a messageBlock with a message
unknownAcceptAccept

The "fail open" rule

If verification does not answer in time or returns an error, accept the address and log the event. An outage or exhausted credits must never block sign-ups or orders. You can monitor your balance with GET /api/v1/credits (the low_balance field).

5. Handling HTTP errors

CodeCauseResponse
401Wrong or revoked key, or a request from outside the allowed IPsAlert the team, accept the address
402No credits leftAlert, top up the balance, accept the address
422Invalid inputCheck what you send (only the email field)
429Rate limit exceededRetry with increasing delay
503Service temporarily unavailableRetry shortly or accept the address

Every error uses the same JSON envelope with code, message and request_id. Logging the request ID is worth it: it speeds up resolving an issue with support.

6. Whole lists: batch verification

To check an existing database (e.g. before a campaign), do not call /verify in a loop. Upload a CSV file as a job:

  1. POST /api/v1/jobs with the file and the name of the column with the addresses; the Idempotency-Key header prevents a duplicate job when you retry.
  2. GET /api/v1/jobs/{job_id} every few seconds until the status changes to completed.
  3. GET /api/v1/jobs/{job_id}/export to download a CSV with the results (optionally only a chosen status).

Addresses the recipient's server temporarily refused to check (greylisting) are retried by the job automatically. Their number is shown in progress.waiting_rows.

  1. Keep the API key on the server only, in an environment variable.
  2. Protect your own endpoint with rate limits and a CAPTCHA.
  3. Verify when the field loses focus and on submit, not on every character.
  4. Show typos as a suggestion; block disposable and invalid addresses.
  5. On errors and timeouts, accept the address (fail open) and log the request_id.
  6. Check existing lists with CSV jobs, not with a loop of single requests.

Keep your contact list clean

Verify email addresses before you send, and explore our upcoming SPF/DKIM/DMARC diagnostics module.

Try MailSpecto

MailSpecto Engineering Team

We build tools for email address verification, deliverability monitoring and mail infrastructure security diagnostics for companies in Poland and Europe.

Related articles

API and integrations

How to prepare a CSV file for email verification

Encoding, delimiters, the email column, duplicates and limits: how to prepare a CSV file for list verification.

Read article →
Compliance

Article 24 of the Polish anti-abuse act – what public bodies must do about email

Who Article 24 of the Polish UZNKE covers, what it requires from public bodies and email providers, the new definition of a public entity from 3 April 2026, inspections by the UKE President, penalties and a checklist.

Read article →
SPF, DKIM and DMARC

DMARC reports – how to read them and move from p=none to p=reject

How to read DMARC aggregate reports (rua) and move step by step from p=none to p=quarantine and p=reject.

Read article →