npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

email-domain-check

v2.0.5

Published

Comprehensive email domain validation library with DNS, MX, SMTP, DKIM, DMARC and MTA-STS support.

Readme

email-domain-check

A comprehensive email domain validation library. Supports DNS, MX, SMTP, DKIM, DMARC, and MTA-STS.

version downloads node

Features

  • MX record validation
  • SMTP server connection testing
  • DKIM record lookup
  • DMARC policy validation
  • MTA-STS support (RFC 8461)
  • IPv4/IPv6 support
  • Local IP blocking
  • DNS failover resolvers
  • Punycode/IDN support
  • TypeScript support

Installation

npm install email-domain-check
# or
pnpm add email-domain-check
# or
yarn add email-domain-check
# or
bun add email-domain-check

Usage (ESM / TypeScript)

import { Address, DomainChecker } from 'email-domain-check';

const checker = new DomainChecker();

// Check if domain has MX records
const hasMx = await checker.hasMxRecord('[email protected]');
console.log('Has MX:', hasMx);

// Get MX records with priority
const mxRecords = await checker.getMxRecord({
	target: 'gmail.com', // string, URL or Address
	useCache: false,
	preferDomainNS: false, // use authoritative ns `ns1.google.com`
});
console.log('MX Records:', mxRecords);
// [{ exchange: 'gmail-smtp-in.l.google.com', priority: 5 }]

// use url, domain or email
const url = new URL('https://gmail.com');
const addr_01 = Address.loadFromTarget(url);
const addr_02 = Address.loadFromTarget('gmail.com');
const addr_03 = Address.loadFromTarget('[email protected]');
const addr_04 = new Address('[email protected]'); // email or domain

console.log('Has MX 01:', await checker.hasMxRecord(addr_01));
console.log('Has MX 02:', await checker.hasMxRecord(addr_02));
console.log('Has MX 03:', await checker.hasMxRecord(addr_03));
console.log('Has MX 04:', await checker.hasMxRecord(addr_04));
// or direct use
console.log('Has MX 05:', await checker.hasMxRecord(new URL('https://gmail.com')));
console.log('Has MX 06:', await checker.hasMxRecord('gmail.com'));
console.log('Has MX 07:', await checker.hasMxRecord('[email protected]'));
console.log('Has MX 08:', await checker.hasMxRecord('[email protected]'));

Usage (CommonJS)

const { DomainChecker } = require('email-domain-check');

async function run() {
	const checker = new DomainChecker();

	// Check if domain has MX records
	const hasMx = await checker.hasMxRecord('[email protected]');
	console.log('Has MX:', hasMx);

	// Get MX records with priority
	const mxRecords = await checker.getMxRecord({
		target: 'gmail.com', // string, URL or Address
		useCache: false,
		preferDomainNS: false, // use authoritative ns `ns1.google.com`
	});
	console.log('MX Records:', mxRecords);
	// [{ exchange: 'gmail-smtp-in.l.google.com', priority: 5 }]
}

run();

Advance Usage

Get Records

import { DomainChecker } from 'email-domain-check';

const checker = new DomainChecker();

// Get SPF record
const spf = await checker.getSpfRecord({
	target: '[email protected]',
	dkimSelector: 'k1',
});
console.log('SPF:', spf);

// Get DKIM record
const dkim = await checker.getDkimRecord({
	target: '[email protected]',
	dkimSelector: 'k1',
});
console.log('DKIM:', dkim);

// Get DMARC record
const dmarc = await checker.getDmarcRecord({
	target: 'gmail.com',
});
console.log('DMARC:', dmarc);

// Get MTA-STS record
const sts = await checker.getStsRecord({
	target: '[email protected]',
});
console.log('MTA-STS:', sts);

// Get custom records
const customRecords = await checker.getCustomRecords({
	target: '[email protected]',
});
console.log('Custom Records:', customRecords);

// Get custom kv record
const kvRecord = await checker.getCustomKVRecord(
	{
		target: '[email protected]',
	},
	'yahoo-verification-key',
);
console.log('KV Record:', kvRecord);

// Get custom kv record
const allKVRecord = await checker.getAllKVRecords({
	target: '[email protected]',
});
console.log('All KV Records:', allKVRecord);

Get Authoritative Name Servers

import { DomainChecker } from "email-domain-check";
const checker = new DomainChecker();

// Get name servers
const nameServers = await checker.getNameServers("gmail.com");
console.log("Name Servers:", nameServers);

Get SMTP Connection

import { DomainChecker } from "email-domain-check";

const checker = new DomainChecker();
// Test or Get SMTP connection for mail sending
const socket = await checker.getSmtpConnection("[email protected]");
if (socket) {
  console.log("SMTP connection successful");
  socket.end();
}

MTA-STS Policy

import { getMtaStsPolicy, isMxAllowed } from "email-domain-check";

const policy = await getMtaStsPolicy("gmail.com");
if (policy) {
  console.log("MTA-STS Policy:", policy);
  // { version: 'STSv1', mode: 'enforce', mx: ['*.google.com'], max_age: 86400 }
  
  const allowed = isMxAllowed("alt1.gmail-smtp-in.l.google.com", policy);
  console.log("MX Allowed:", allowed);
}

Address Parsing and Validation

import {Address } from "email-domain-check";
// Address parsing and validation
const addr = Address.loadFromTarget("[email protected]");
console.log("Hostname:", addr.hostname); // example.com
console.log("User:", addr.user); // user
console.log("Is IP:", addr.isIP); // false
console.log("Is Local:", addr.isLocal); // false
console.log("Has Punycode:", addr.hasPunycode); // false

// Parse from URL
const url = new URL("https://example.com/path");
const urlAddr = Address.loadFromTarget(url);
console.log("From URL:", urlAddr.hostname); // example.com

// IP address validation
const Addr_01 = new Address("192.168.1.1");
console.log("Is Local IP:", Addr_01.isLocal); // true

const Addr_02 = new Address("8.8.8.8");
console.log("Is Local IP:", Addr_02.isLocal); // false

API

DomainChecker Class

Constructor Options

interface DomainCheckerOptions {
  server?: string[];            // Custom DNS servers
  dkimSelector?: string;        // Default: 'default'
  useCache?: boolean;           // Enable DNS caching
  cacheTTL?: number;            // Cache TTL in ms
  smtpTimeout?: number;         // Default: 10000
  dnsTimeout?: number;          // Default: 5000
  httpTimeout?: number;         // Default: 8000
  socketIdleTimeout?: number;   // RFC 5321 socket idle timeout
  useDomainNS?: boolean;        // Query domain's authoritative nameservers (Default: false)
  useMtaSts?: boolean;          // Enable MTA-STS related lookups (Default: false)
  ignoreIPv6?: boolean;         // Ignore IPv6 addresses
  tries?: number;               // Default: 3
  failoverServers?: string[][]; // Default: [['1.1.1.1','1.0.0.1'], ['8.8.8.8','8.8.4.4']]
  blockLocalIPs?: boolean;      // Block local/private IPs (Default: false)
  deliveryPort?: number;        // Default: 25
}

Methods

  • hasMxRecord(target: Target): Promise<boolean> - Check if domain has MX records
  • getMxRecord(options: ResolveOptions): Promise<MxRecord[]> - Get MX records
  • getSmtpConnection(target: Target): Promise<Socket | null> - Test SMTP connection
  • getTxtRecord(options: ResolveOptions): Promise<TXTResult | null> - Get all TXT records parsed
  • getSpfRecord(options: ResolveOptions): Promise<SPF1Record | null> - Get SPF record
  • getDkimRecord(options: ResolveOptions): Promise<DKIM1Record | null> - Get DKIM record
  • getDmarcRecord(options: ResolveOptions): Promise<DMARC1Record | null> - Get DMARC record
  • getStsRecord(options: ResolveOptions): Promise<STSv1Record | null> - Get MTA-STS record
  • getCustomRecords(options: ResolveOptions): Promise<CustomRecord[] | null> - Get custom TXT records
  • getCustomKVRecord(options: ResolveOptions, key: string): Promise<CustomKVRecord | null> - Get specific key-value record
  • getAllKVRecords(options: ResolveOptions): Promise<CustomKVRecord[] | null> - Get all key-value records
  • getNameServers(target: Target): Promise<string[]> - Get authoritative name servers

Address Class

Constructor

  • new Address(mailOrHost: string) - Create new Address instance
import {Address } from "email-domain-check";
const addr_01 = new Address('[email protected]'); // string email or domain
const addr_02 = new Address('gmail.com'); 

Static Constructor Method

  • Address.loadFromTarget(target: string | URL | Address): Address - Parse email/domain/URL

Properties

  • source: string - Original input
  • hostname: string - Domain name or IP
  • user?: string - Email local part (if email)
  • ipKind: IPKind - IP type (None, IPv4, IPv6)
  • isIP: boolean - Is an IP address
  • isLocal: boolean - Is local/private IP
  • hasPunycode: boolean - Contains punycode