Dev.to WebDev 🛠 Dev 👁 0 📖 1 min read

Why Regex Alone Fails Email Verification (And How to Check MX and Role Accounts in TypeScript)

Most signup forms and outbound pipelines validate email addresses with a regular expression and stop there. Syntax checks catch missing @ symbols, yet they happily pass typos like [email protected], expired domains, and shar

Most signup forms and outbound pipelines validate email addresses with a regular expression and stop there. Syntax checks catch missing @ symbols, yet they happily pass typos like [email protected], expired domains, and shared distribution inboxes that damage your sender reputation.

To protect deliverability before sending a single message, your validation layer needs two additional checks: DNS MX record resolution and role account detection.

1. Reject Role Accounts in Automated Outreach

Generic addresses such as info@, sales@, support@, admin@, and billing@ are shared across teams or piped into ticketing systems. Sending automated outreach to role inboxes leads to much higher spam complaint rates and trap hits.

You can filter them deterministically in TypeScript:

const ROLE_PREFIXES = new Set([
  "info",
  "sales",
  "support",
  "contact",
  "hello",
  "admin",
  "help",
  "billing",
  "office",
  "team",
  "noreply",
]);

export function isRoleAccount(email: string): boolean {
  const localPart = email.split("@")[0]?.toLowerCase().trim() ?? "";
  return ROLE_PREFIXES.has(localPart);
}

2. Verify Authoritative DNS MX Records

Even if an address looks valid, a domain without MX records cannot receive mail. Using Node or Bun's built in node:dns/promises resolver lets you check MX availability with zero external dependencies:

import { resolveMx } from "node:dns/promises";

export async function hasValidMx(domain: string): Promise<boolean> {
  try {
    const records = await resolveMx(domain);
    return records.length > 0 && records.some((r) => r.exchange.length > 0);
  } catch {
    return false;
  }
}

3. Combine Checks Before Opening an SMTP Socket

Before queuing an email or writing a lead into your database, run syntax validation, disposable domain filtering, role account quarantine, and DNS MX verification together. If a domain fails MX resolution or returns a hard bounce during delivery, purge the dead record immediately rather than retrying.

💡 Developer Infrastructure Note: If you want active Port 25 SMTP mailbox verification and catch all detection out of the box, SadaSend runs pre send bounce checks in flight and blocks dead addresses before they hurt your domain reputation.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.