Limited-time August offer: Save 80% on email verification credits. View pricing
Tutorial · JavaScript

Verify Email Addresses with JavaScript

Real-time email verification in Node.js with the built-in fetch API — no extra dependencies required.

GET https://api.validemail.net/ 1 credit per verification Node.js 18+
1

Verify an email address

Send a GET request with the email and your API token. The helper below also handles interim Unknown results by waiting RetryAfterSeconds and retrying automatically.

JavaScript (Node.js)
const API_URL = 'https://api.validemail.net/';
const API_KEY = 'YOUR_API_KEY'; // find it in your ValidEmail dashboard

const sleep = (seconds) => new Promise((resolve) => setTimeout(resolve, seconds * 1000));

async function verifyEmail(email, maxRetries = 3) {
  let result;

  for (let attempt = 0; attempt < maxRetries; attempt++) {
    const params = new URLSearchParams({ email, token: API_KEY });
    const response = await fetch(`${API_URL}?${params}`);

    if (!response.ok) {
      throw new Error(`Request failed: ${response.status} ${await response.text()}`);
    }

    result = await response.json();

    // "Unknown" means the verification is still in progress (e.g. greylisting).
    if (result.State === 'Unknown' && result.RetryAfterSeconds) {
      await sleep(result.RetryAfterSeconds);
      continue;
    }

    return result;
  }

  return result; // still pending after maxRetries — treat as risky
}

const result = await verifyEmail('someone@example.com');

console.log(`Valid:  ${result.IsValid}`);
console.log(`Score:  ${result.Score}`);
console.log(`State:  ${result.State}`);
console.log(`Reason: ${result.Reason}`);

if (result.IsValid && result.Score >= 80) {
  console.log('Safe to send.');
}
Handling interim results (State = "Unknown")

Some mail servers greylist first-time senders or respond slowly. Instead of failing, the API returns an interim 200 OK result with State = "Unknown", a Reason of PENDING or GREYLISTED, and a RetryAfterSeconds hint while the verification finishes in the background.

  • Wait RetryAfterSeconds seconds, then repeat the same request to get the final verdict.
  • Definitive results are cached for about 10 minutes, so the retry is answered instantly once the verification completes.
  • Treat Unknown as "not yet decided" — never as a delivery failure.

Server-side only. Never call the API from browser code — that would expose your API key to anyone viewing the page source. Keep requests on your backend.

2

Check your credits balance

The balance endpoint is free to call and never consumes a credit — perfect for a pre-flight check before verifying a large list.

JavaScript (Node.js)
const response = await fetch(`https://api.validemail.net/balance?token=${API_KEY}`);
const { balance } = await response.json();

console.log(`Credits remaining: ${balance}`);

HTTP status codes

HTTP Status Meaning What to do
200 OK The request was processed. Check State — a result with State = "Unknown" and a RetryAfterSeconds value is an interim answer, not a final verdict. Use the result. If State is Unknown, retry the same request after RetryAfterSeconds.
400 Bad Request Missing email/token parameter, no credits remaining, or a transient processing failure. Check the response text. If you are out of credits, top up your balance before retrying.
401 Unauthorized The API key is invalid or unknown. Verify the token value against the API key shown in your dashboard.
403 Forbidden The account attached to this API key is inactive. Contact info@validemail.net to reactivate the account.
429 Too Many Requests You exceeded your per-second request limit. The response body includes the configured limit. Slow down and retry with backoff, or contact us to raise your rate limit.
Next steps

Explore every response field and status code in the full API reference.