๐Ÿš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more โ†’
Socket
DemoInstallSign in
Socket

mail-validatr

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mail-validatr

Email validation CLI and library with DNS, MX, and warning checks.

1.0.3
latest
Source
npm
Version published
Weekly downloads
52
-60.9%
Maintainers
1
Weekly downloads
ย 
Created
Source

mail-validatr

mail-validatr is a lightweight Node.js library and CLI tool for validating email addresses.
It checks syntax, domain validity, and MX records to ensure an email address is not just well-formed, but also likely to exist.

npm license CI

Features

  • ๐Ÿ“ฌ Syntax Validation โ€” Checks if an email matches standard formats.
  • ๐ŸŒ Domain Verification โ€” Verifies if the domain is real and reachable.
  • ๐Ÿ“จ MX Record Lookup โ€” Confirms that the domain accepts emails (via MX records).
  • โšก Fast and Lightweight โ€” Minimal dependencies, fast execution.
  • ๐Ÿ› ๏ธ CLI and Programmatic API โ€” Use in scripts or integrate into your Node.js apps.
  • ๐Ÿ›ก๏ธ Custom Rules โ€” Add custom validation rules or disposable email lists.
  • โœ… Recommended Check โ€” Indicates if the email is valid and free of warnings.

Installation

Install the library via npm:

npm install mail-validatr

For global CLI usage:

npm install -g mail-validatr

Usage

Programmatic (Node.js)

Import and use the validateEmail function:

import { validateEmail } from "mail-validatr";

async function checkEmail() {
  const result = await validateEmail("user@example.com");
  console.log(result);
}

checkEmail();

Example output:

{
  "isValidSyntax": true,
  "hasValidDomain": true,
  "hasMxRecords": true,
  "warnings": [],
  "recommended": true
}

Skipping DNS Checks

For environments without network access, you can skip DNS and MX record validation:

await validateEmail("user@example.com", { skipDnsCheck: true });

Adding Custom Warning Rules

You can define custom rules for additional validation:

const customRules = [
  (email: string) =>
    email.endsWith("@example.com")
      ? { code: "example_com_not_allowed", message: "Emails from example.com are not allowed." }
      : null,
];

await validateEmail("user@example.com", { customWarningRules: customRules });

Example output with warnings:

{
  "isValidSyntax": true,
  "hasValidDomain": true,
  "hasMxRecords": true,
  "warnings": [
    {
      "code": "example_com_not_allowed",
      "message": "Emails from example.com are not allowed."
    }
  ],
  "recommended": false
}

CLI

Validate email addresses directly from the command line:

mail-validatr user@example.com

Output:

[RESULT] Validation result for user@example.com:
- Syntax valid: true
- Domain valid: true
- MX records found: true
- Warnings: None
- Recommended: Yes

Skipping DNS Checks

Use the --skip-dns flag to skip DNS and MX record validation:

mail-validatr user@example.com --skip-dns

Verbose Output

Enable verbose output with the --verbose flag:

mail-validatr user@example.com --verbose

API

validateEmail(email: string, options?: ValidationOptions): Promise<EmailValidationResult>

Parameters:

  • email (string): The email address to validate.
  • options (object, optional):
    • skipDnsCheck (boolean): If true, skips DNS and MX record validation.
    • customDisposableList (string[]): Add custom disposable email domains.
    • customWarningRules (Array<(email: string) => { code: string; message: string } | null>): Add custom warning rules.

Returns:

An EmailValidationResult object:

interface EmailValidationResult {
  isValidSyntax: boolean;
  hasValidDomain?: boolean;
  hasMxRecords?: boolean;
  warnings: Array<{ code: string; message: string }>;
  recommended: boolean;
}

๐Ÿงช Example Projects

You can see real-world usage of mail-validatr in action:

This repository contains:

  • Client Demo โ€” Frontend-only validation with syntax + warning checks (Next.js + React + Tailwind).
  • Server Demo โ€” Full email validation with DNS & MX lookup using server routes.

Useful Scripts

  • Build: npm run build
  • Dev Mode (watch + test): npm run dev:test
  • Run Tests: npx vitest

License

MIT ยฉ 2025
Made with โค๏ธ by Jindrich Bobek

Keywords

email

FAQs

Package last updated on 03 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts