To check if an email exists in Node.js you need two things: a cheap local check (format and the domain's MX records, both possible with
Node's standard library) and a mailbox check, which needs an SMTP conversation your app server usually can't have. This page shows the
local checks first, then how to verify the mailbox with built-in fetch: one address or a whole list, no npm packages.
TL;DR
dns.promises.resolveMx()tells you whether a domain can receive mail. It can't tell you whetherjane@exists: that takes an SMTP check, and AWS and Google Cloud block outbound port 25 by default.- The Mail Exchange API is plain HTTPS and JSON at
https://mailexchange.com/api/v1. No SDK needed. POST /verifychecks one address and usually answers in a few seconds.POST /listschecks up to 100,000 addresses and you poll for the result.- Each result has a
state: deliverable, risky, undeliverable or unknown. The decision function below turns that into send, separate, skip, remove or retry. - Handle three statuses and you are done:
202(still checking),402(out of credits) and429(slow down).
Get an API key and set up
Create an API key in your account (sign up, then open API keys). Every request sends the key as
Authorization: Bearer your_key. Keep it in an environment variable, as the examples do, and out of source control. Checks are
paid from your plan's monthly verifications: plans start at $49 a month for 10,000 verifications and daily checks on 10 sending domains, every plan includes the API, and unknown results and duplicates are
refunded (see pricing).
Node.js 18 or newer (for built-in fetch). No npm packages. Use the .mjs extension for top-level await.
fetch does not throw on a 4xx or 5xx, which is why the helper checks res.ok itself.
Check if an email exists in Node.js: the local checks
Before you spend a credit, reject what you can locally. Node has no built-in email validator, but it does have a DNS resolver, and the MX lookup is the most useful free check there is.
import { promises as dns } from "node:dns";
// 1. Format: deliberately loose. One @, something on each side, a dot in the domain.
const looksLikeEmail = (s) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s);
// 2. Can the domain receive mail? MX first; RFC 5321 falls back to the A record.
async function domainAcceptsMail(domain) {
try {
const mx = await dns.resolveMx(domain);
if (mx.length > 0) return true;
} catch (err) {
if (err.code !== "ENODATA" && err.code !== "ENOTFOUND") throw err; // timeouts etc.: retry later
if (err.code === "ENOTFOUND") return false; // the domain doesn't exist
}
try {
return (await dns.resolve4(domain)).length > 0; // implicit MX
} catch {
return false;
}
}
console.log(looksLikeEmail("[email protected]"), await domainAcceptsMail("acme.com"));
resolveMx is part of Node's DNS module.
The A-record fallback follows RFC 5321 section 5.1, which
treats a domain's address record as an implicit MX when no MX exists (both checked 2026-11-22).
What these checks catch in practice is small. In Mail Exchange's checks of 779,784 unique business addresses (17 Oct to 22 Nov 2026, mostly B2B contact lists sent through our API), only 100 (about 0.01%) failed syntax and 6,854 (0.9%) were on domains that don't receive mail. The bigger groups need a mailbox check: 52,136 (6.7%) mailboxes were rejected by the mail server, and 18.1% of addresses sat on catch-all domains that accept anything.
Verify one address in Node.js
Save this as mx-one.mjs. It defines a small call helper that sends the key, retries on 429, and turns error responses into an exception or error value with the message from the API. Then verify_one posts the address and handles the one tricky case: a slow mail server.
import { readFileSync } from "node:fs";
const BASE = "https://mailexchange.com/api/v1";
const API_KEY = process.env.MAILEXCHANGE_API_KEY;
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
class MXError extends Error {
constructor(status, message) {
super(`HTTP ${status}: ${message}`);
this.status = status;
}
}
// One API call. Retries 429 with exponential backoff, throws MXError on other errors.
async function call(method, path, body, retries = 4) {
for (let attempt = 0; ; attempt++) {
const res = await fetch(BASE + path, {
method,
headers: { Authorization: `Bearer ${API_KEY}`, "Content-Type": "application/json" },
body: body === undefined ? undefined : JSON.stringify(body),
signal: AbortSignal.timeout(45_000),
});
if (res.status === 429 && attempt < retries) {
await sleep(2 ** attempt * 1000);
continue;
}
const data = await res.json().catch(() => ({}));
if (!res.ok) throw new MXError(res.status, data.error ?? res.statusText);
return { status: res.status, data };
}
}
// Turn a result into an action: send, separate, skip, remove or retry.
function decide(result) {
switch (result.state) {
case "deliverable":
return "send";
case "risky":
// low_deliverability = catch-all domain. low_quality = role address, or disposable.
return result.reason === "low_deliverability" ? "separate" : "skip";
case "undeliverable":
return "remove";
default:
return "retry"; // unknown, or still pending
}
}
async function verifyOne(email) {
const { status, data } = await call("POST", "/verify", { email });
if (status !== 202) return data;
// 202: the mail server is slow. The check is running and already paid for.
// Do not post the address again, poll the list instead.
for (let i = 0; i < 36; i++) {
await sleep(5000);
const { data: page } = await call("GET", `/lists/${data.list_id}/results?limit=1`);
const row = page.results[0];
if (row && row.state !== "pending") return row;
}
return data; // still pending after 3 minutes: look again later with the same list_id
}
try {
const res = await verifyOne(process.argv[2]);
console.log(res.email, res.state, res.reason, "->", decide(res));
} catch (err) {
console.error("Mail Exchange error:", err.message);
process.exit(1);
}
Run it:
MAILEXCHANGE_API_KEY=mx_live_xxx node mx-one.mjs [email protected]
/verify waits about 20 seconds and then returns 202 with {"state": "pending", "list_id": ...}. That check is already running and was already charged. Posting the same address again would start a second check and charge again, so read the result from /lists/{list_id}/results instead, as the code does. More in errors, credits and rate limits.Read the result and decide what to do
A result is a flat JSON object: email, state, reason, score, and the flags accept_all, role, free, disposable, plus mx. The state is what you branch on. The reason tells you why, and matters for the risky group. The decide function in the code above maps it like this:
| state | reason | decide() returns | Why |
|---|---|---|---|
| deliverable | accepted_email | send | The mail server accepted the mailbox. |
| risky | low_deliverability | separate | Catch-all domain. Cannot be confirmed either way. Send carefully or keep apart. |
| risky | low_quality, disposable | skip | Role address (info@, sales@) or a throwaway domain. |
| undeliverable | rejected_email, invalid_domain, invalid_email | remove | Will bounce. Drop it. |
| unknown | unavailable_smtp, no_connect, dns_error | retry | The server did not give a clear answer. The credit is refunded. |
A cold email team might send separate addresses only from established inboxes, as described in catch-all emails and cold email. The full list of states is in email verification statuses, and how it works explains the six checks behind them.
Verify a list in Node.js
For more than a handful of addresses, submit one list instead of looping over /verify. You get a list ID straight away, poll GET /lists/{id} until its status is done (or failed), then page through /lists/{id}/results 1,000 rows at a time. Duplicates inside the list are removed and not charged. Save this as mx-list.mjs with one address per line in emails.txt.
import { readFileSync } from "node:fs";
// Paste BASE, API_KEY, sleep, MXError, call() and decide() from the first example here.
async function verifyList(emails) {
const { data: created } = await call("POST", "/lists", { emails, name: "node-example" });
let summary;
for (;;) {
({ data: summary } = await call("GET", `/lists/${created.id}`));
console.log(`${summary.checked}/${summary.total} checked (${summary.status})`);
if (summary.status === "done" || summary.status === "failed") break;
await sleep(5000);
}
if (summary.status === "failed") throw new Error(`list ${created.id} failed`);
const results = [];
for (let offset = 0; ; offset += 1000) {
const { data } = await call("GET", `/lists/${created.id}/results?offset=${offset}&limit=1000`);
results.push(...data.results);
if (data.results.length < 1000) break;
}
return { summary, results };
}
try {
const emails = readFileSync(process.argv[2], "utf8")
.split(/\r?\n/).map((s) => s.trim()).filter(Boolean);
const { summary, results } = await verifyList(emails);
console.log("counts:", summary.counts, "duplicates removed:", summary.duplicates_removed);
const buckets = {};
for (const row of results) (buckets[decide(row)] ??= []).push(row.email);
for (const [action, addresses] of Object.entries(buckets)) console.log(action, addresses.length);
await call("DELETE", `/lists/${summary.id}`); // optional: remove the list and its results
} catch (err) {
console.error("Mail Exchange error:", err.message);
process.exit(1);
}
MAILEXCHANGE_API_KEY=mx_live_xxx node mx-list.mjs emails.txt
Instead of polling you can pass a callback_url and let us call you when the list is done, see webhooks and callbacks. The whole flow, including CSV download and deleting a list, is in verify a list with the API.
Errors, 402 and 429
Every error response is JSON with an error field, which the helper surfaces in the exception message. The ones to plan for:
- 429 means you hit the per-key rate limit. The helper waits 1, 2, 4 and 8 seconds and tries again, which is safe because a rate-limited request does no work and costs nothing.
- 402 means you do not have enough credits for the request. Retrying will not help. Stop, alert someone, and upgrade your plan or wait for it to renew.
GET /accountreturns your balance if you want to check first. - 401 means the key is missing or wrong. 400 means the request was malformed, for example no
email, or a list over 100,000 addresses.
Details and a status code table are in errors, credits and rate limits.
Frequently asked questions
How do I check if an email exists in Node.js?
Check the format with a loose regex, then call dns.promises.resolveMx on the domain to confirm it can receive mail. To confirm the mailbox itself, you need an SMTP check, which most cloud servers can't make because port 25 is blocked, so call a verification API such as POST /verify.
Can I validate an email address without sending an email in Node.js?
Yes. A verification API asks the recipient's mail server whether the mailbox exists and stops before any message is sent. Mail Exchange never sends an email during a check.
Is there an official Node.js SDK for the Mail Exchange API?
No, and none is needed. The API is plain HTTPS and JSON, so the examples on this page use only the standard library.
How do I get an API key?
Create a key in your account dashboard under API keys, after signing up. Send the key as a bearer token in the Authorization header. Checks use your plan's monthly verifications (every plan includes the API), and they reset every month; unused ones don't carry over.
What should I do when /verify returns 202?
Don't resend the address: the check is running and paid for. Read the result from /lists/{list_id}/results using the list_id in the 202 response, until the state is no longer pending.
Want to try it on real addresses first? The free trial gives you 25 checks in the web app, or paste a single address into the free email checker.
Related
- Email verification API reference
- How to verify an email without sending
- Verify a list with the API
- Webhooks and callbacks
- Errors, credits and rate limits
- Pricing and all developer guides
- Email verification API for Python
- Email verification API for PHP
- Email verification API for Ruby
- Email verification API for Go
- Email verification API for Java
- Email verification API for C#
