# Check if an Email Exists in Node.js: DNS, SMTP and an API

To check whether an email address exists in Node.js, check the format, look up the domain's mail servers with `dns.resolveMx` from `node:dns/promises`, then ask one of those servers over SMTP on port 25 whether it accepts the mailbox. Node does the first two with no dependencies. The third often fails from a cloud server, because AWS and Google Cloud block outbound port 25 by default, and Azure does too except on Enterprise Agreement and MCA-E subscriptions, so the last step here is an API call that runs it for you.

The code needs Node 18 or later and was run on Node 25.0.0 on 19 November 2026.

## Step 1: check the format

Split at the last `@`, check both halves, and convert an international domain to ASCII. `url.domainToASCII` returns an empty string for an invalid domain. ([Source](https://nodejs.org/api/url.html))

```javascript
import dns from 'node:dns/promises';
import { domainToASCII } from 'node:url';

// Step 1: format. A typo-and-junk filter, not a full RFC 5321 parser.
export function splitAddress(email) {
  if (typeof email !== 'string') return null;
  const at = email.lastIndexOf('@');
  if (at < 1 || at === email.length - 1) return null;
  const local = email.slice(0, at);
  const domain = domainToASCII(email.slice(at + 1)); // "" if the domain is invalid
  if (Buffer.byteLength(local) > 64 || /\s/.test(local)) return null; // RFC 5321: local part is at most 64 octets
  if (!/^[a-z0-9-]+(\.[a-z0-9-]+)+$/i.test(domain)) return null;
  return { local, domain };
}
```

`ana@bücher.de` comes back with the domain `xn--bcher-kva.de`, the form DNS needs. The 64-octet limit is from RFC 5321, section 4.5.3.1.1. ([Source](https://www.rfc-editor.org/rfc/rfc5321))

## Step 2: look up the mail servers

`dnsPromises.resolveMx` resolves to an array of `{ priority, exchange }` objects. ([Source](https://nodejs.org/api/dns.html)) Four cases matter:

- **Null MX.** A domain that takes no mail can publish one MX record whose host is `.` (RFC 7505). ([Source](https://www.rfc-editor.org/rfc/rfc7505)) In our test, Node returned that host as an empty string.
- **No such domain.** The lookup fails with `ENOTFOUND`.
- **No MX records.** Mail goes to the domain's own address record, the "implicit MX" of RFC 5321, section 5.1. ([Source](https://www.rfc-editor.org/rfc/rfc5321))
- **DNS failure or timeout.** No answer yet.

```javascript
// Step 2: does the domain take mail at all? Returns 'yes', 'no' or 'unknown'.
export async function acceptsMail(domain) {
  let mx = [];
  try {
    mx = await dns.resolveMx(domain);
  } catch (err) {
    if (err.code === dns.NOTFOUND) return 'no'; // the domain does not exist
    if (err.code !== dns.NODATA) return 'unknown'; // SERVFAIL, TIMEOUT and so on: try again later
  }
  // Null MX (RFC 7505): one record with host ".", meaning "no mail here". Node 25 returned "" for it.
  if (mx.length === 1 && ['', '.'].includes(mx[0].exchange)) return 'no';
  if (mx.length > 0) return 'yes';

  // No MX records. RFC 5321 then treats the domain's own address record as the mail host.
  try {
    await Promise.any([dns.resolve4(domain), dns.resolve6(domain)]);
    return 'yes';
  } catch (err) {
    const gone = err.errors.every((e) => e.code === dns.NODATA || e.code === dns.NOTFOUND);
    return gone ? 'no' : 'unknown';
  }
}
```

Results:

| Domain | DNS | `acceptsMail` |
|---|---|---|
| `gmail.com` | 5 MX records | `yes` |
| `example.com` | Null MX | `no` |
| A made-up `.com` domain | `ENOTFOUND` | `no` |
| `neverssl.com` | No MX, has an address record | `yes` |
| `_dmarc.gmail.com` | No MX, no address record | `no` |

A `yes` means the domain takes mail, not that the mailbox exists.

## Step 3: why an SMTP probe from your own server is hard

The mailbox check is a short SMTP conversation: connect on port 25, send `EHLO`, `MAIL FROM` and `RCPT TO` with the address, read the reply, then send `RSET` and `QUIT` instead of `DATA`, so no message is sent. [How to check if an email address exists](/blog/check-if-email-exists) walks through it by hand. Writing it is easy. Getting a useful answer is not.

**Port 25 may be blocked.** Each provider differs:

- **AWS.** "By default, Amazon EC2 allows outbound traffic over port 25 only to private IPv4 addresses. Traffic over port 25 is blocked to public IPv4 addresses and IPv6 addresses." You can ask AWS to remove the restriction. ([Source](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-resource-limits.html))
- **Google Cloud.** By default it "blocks egress packets sent to TCP destination port 25 of an external IP address". It lifts the block once it decides a project is low risk. ([Source](https://cloud.google.com/firewall/docs/firewalls))
- **Azure.** Enterprise Agreement and MCA-E subscriptions are not blocked. Enterprise Dev/Test is blocked by default, and you can ask Azure to lift it. For "all other subscription types", Azure "blocks outbound SMTP connections on TCP port 25 for deployed VMs." ([Source](https://learn.microsoft.com/en-us/azure/virtual-network/troubleshoot-outbound-smtp-connectivity))

**Greylisting.** Some servers answer a sender they don't know with a temporary 4xx failure and accept only a later retry. RFC 6647 describes it as "degradation of service for an unknown or suspect source". ([Source](https://www.rfc-editor.org/rfc/rfc6647)) A one-shot probe gets "try later", not a yes or no.

**Catch-all domains.** Some domains accept every address. They answer `250` for a real mailbox and for a made-up one, so one `RCPT TO` cannot tell them apart.

**Refusals of unknown senders.** A server can refuse your IP address rather than the mailbox, and the reply is still a refusal. [SMTP error codes explained](/blog/smtp-error-codes-explained) shows how to tell the two apart. PingValid meets this too: addresses at some providers, T-Online for example, may come back `unknown`.

## Step 4: call the PingValid API

PingValid runs syntax, domain, MX, disposable-domain, role-account and SMTP mailbox checks in one request, plus catch-all detection on the Deep tier. It returns one verdict: `valid`, `risky`, `invalid` or `unknown`.

Send `POST https://pingvalid.com/v1/validate` with your `pv_live_…` key as a Bearer token and the body `{"email": "..."}`, up to 320 characters. The optional `tier` is `quick` (no SMTP check), `standard` (the default) or `deep` (needs a paid plan or a top-up). Always send `Accept: application/json`: without it, a `422` comes back as a redirect to an HTML page and a `429` as HTML.

`fetch` is built into Node 18 and later. ([Source](https://nodejs.org/api/globals.html))

```javascript
const TIMEOUT_MS = 10_000; // yours to choose

// Step 4: ask PingValid. Pass the same idempotencyKey again if you retry this address.
export async function validate(email, idempotencyKey, tier = 'standard') {
  const res = await fetch('https://pingvalid.com/v1/validate', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.PINGVALID_API_KEY}`, // a pv_live_… key with the validate:single scope
      'Content-Type': 'application/json',
      Accept: 'application/json', // without it, a 422 or 429 comes back as HTML
      'Idempotency-Key': idempotencyKey,
    },
    body: JSON.stringify({ email, tier }),
    signal: AbortSignal.timeout(TIMEOUT_MS),
  });

  if (res.ok) return res.json(); // cost_credits says what this check cost

  // Nothing below is charged.
  const err = new Error(`PingValid answered HTTP ${res.status}`);
  err.status = res.status;
  if (res.status === 429) {
    err.retryAfter = Number(res.headers.get('Retry-After')) || 60; // seconds; the body has no error code
    throw err;
  }
  const body = await res.json().catch(() => ({}));
  err.code = body.error?.code; // unauthorized, insufficient_credits, forbidden, plan_required, invalid_request
  err.detail = body.error?.details ?? body.errors ?? body.message; // the other 422 shape: {message, errors}
  throw err;
}
```

| Status | Meaning |
|---|---|
| `200` | A verdict. `cost_credits` states the charge: 1 on Quick or Standard, 2 on Deep, nothing for `unknown` or for a cached repeat on Quick and Standard |
| `401` | `unauthorized`: the key is missing, wrong or revoked |
| `402` | `insufficient_credits` |
| `403` | `forbidden` (the key lacks the scope) or `plan_required` (Deep without a paid plan or a top-up) |
| `422` | Input it won't check. A malformed address gets `{"error":{"code":"invalid_request",…}}`. A missing or too-long `email`, or a bad `tier`, gets `{"message","errors":{"email":[…]}}` |
| `429` | Rate limited. The body is `{"message":"Too Many Attempts."}`, with no error code. Wait `Retry-After` seconds |

The `401`, `402` and `403` bodies are `{"error":{"code","message"}}`. No error is charged.

In a `200`, `tier_results` is keyed by tier id. Each entry has an `outcome` of `pass`, `fail` or `unknown`, and only the checks that ran appear.

The values from a real check of `postmaster@cloudflare.com` on 2 September 2026, laid out in that response shape and trimmed:

```json
{
  "email": "postmaster@cloudflare.com",
  "verdict": "risky",
  "risk_score": 40,
  "tier_results": {
    "t1_syntax": { "outcome": "pass" },
    "t2_domain": { "outcome": "pass" },
    "t3_mx": { "outcome": "pass" },
    "t4_disposable": { "outcome": "pass" },
    "t5_role": { "outcome": "fail" },
    "t6_smtp": { "outcome": "pass" }
  },
  "cost_credits": 1
}
```

The server accepted the mailbox, yet the verdict is `risky`: `postmaster@` is a role account, not one person's inbox.

## Putting it together

Run the free local checks first. A `422` is free, but an address that gets a verdict is charged, even when the verdict is `invalid`.

```javascript
import { randomUUID } from 'node:crypto';

export async function checkEmail(email, idempotencyKey = randomUUID()) {
  const parts = splitAddress(email);
  if (!parts) return { verdict: 'invalid', reason: 'format' };
  if ((await acceptsMail(parts.domain)) === 'no') return { verdict: 'invalid', reason: 'no mail servers' };
  // 'unknown' from DNS still goes to the API: its own lookup may succeed.
  try {
    return await validate(email, idempotencyKey);
  } catch (err) {
    if (err.status === 422) return { verdict: 'invalid', reason: 'rejected input' };
    throw err; // 401, 402, 403, 429 or a timeout: decide whether to fail open or closed
  }
}
```

Then reject `invalid`, flag `risky`, accept `valid`, and check `unknown` again later. [Why a verifier says "unknown"](/blog/why-email-verifier-says-unknown) explains the causes.

A full signup handler built on this call is in [how to stop fake signups](/blog/stop-fake-signups-saas).

## FAQ

### Can I check if an email exists without sending an email in Node.js?

Yes. The SMTP check stops at `RCPT TO` and never sends `DATA`, so no message is sent.

### Is an MX lookup enough?

No. It shows that the domain takes mail, not that the mailbox exists.

### Can an AI agent run the same check?

Yes, through PingValid's MCP server at `https://pingvalid.com/mcp`. Its `pingvalid_validate_email` tool returns the verdict, risk score and per-check evidence. See the [MCP docs](/docs/mcp).

## Try it on the Free plan

A free PingValid account includes 100 checks a month on the Quick and Standard tiers and needs no card. Deep needs a paid plan or a top-up. [Create a free account](/register), confirm your email, and create a key with the `validate:single` scope. Reference: [API docs](/docs/api). Plans: [pricing](/pricing).