{"id":44385471,"url":"https://github.com/andreinwald/email-validator-dns-provider-rules","last_synced_at":"2026-02-12T00:41:10.279Z","repository":{"id":211549491,"uuid":"729440356","full_name":"andreinwald/email-validator-dns-provider-rules","owner":"andreinwald","description":"Email Validator with checking DNS MX records and strict real-life provider rules","archived":false,"fork":false,"pushed_at":"2025-06-10T16:44:04.000Z","size":111,"stargazers_count":32,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-24T01:20:35.724Z","etag":null,"topics":["dns","email","emailvalidation","gmail","hotmail","mx","validation","yahoo"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/email-validator-dns-provider-rules","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andreinwald.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-12-09T08:29:38.000Z","updated_at":"2025-10-31T07:47:48.000Z","dependencies_parsed_at":"2024-04-07T09:32:56.824Z","dependency_job_id":"9b6cbed8-b49b-406b-a61b-fd22edf7e4a6","html_url":"https://github.com/andreinwald/email-validator-dns-provider-rules","commit_stats":{"total_commits":53,"total_committers":2,"mean_commits":26.5,"dds":"0.037735849056603765","last_synced_commit":"379ff84680a91e936c0ea2fb366f892737c3ae04"},"previous_names":["andreinwald/email-validator-dns-provider-rules"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/andreinwald/email-validator-dns-provider-rules","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreinwald%2Femail-validator-dns-provider-rules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreinwald%2Femail-validator-dns-provider-rules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreinwald%2Femail-validator-dns-provider-rules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreinwald%2Femail-validator-dns-provider-rules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreinwald","download_url":"https://codeload.github.com/andreinwald/email-validator-dns-provider-rules/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreinwald%2Femail-validator-dns-provider-rules/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29351055,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T20:11:40.865Z","status":"ssl_error","status_checked_at":"2026-02-11T20:10:41.637Z","response_time":97,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dns","email","emailvalidation","gmail","hotmail","mx","validation","yahoo"],"created_at":"2026-02-12T00:41:09.623Z","updated_at":"2026-02-12T00:41:10.264Z","avatar_url":"https://github.com/andreinwald.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Email Validator with DNS Check and Provider Rules\n\nA robust email validation library that goes beyond basic regex validation by checking:\n\n1. DNS MX records to verify domain existence\n2. Provider-specific rules for usernames (e.g., Gmail, Yahoo)\n3. Common domain typos (e.g., \"gmial.com\" instead of \"gmail.com\")\n4. Custom domain blocklists\n\n## Why Use This Library?\n\nMost email validators only check basic syntax, allowing many invalid emails to pass. This library catches emails that\nother validators miss:\n\n| Invalid Email                 | Reason                                                                        |\n|-------------------------------|-------------------------------------------------------------------------------|\n| som_e-one@gmail.com           | Gmail doesn't allow \"_\" and \"-\" symbols                                       | \n| someone@8avymt4v93mvt3t03.com | \"8avymt4v93mvt3t03.com\" isn't a real domain and doesn't have DNS MX records   | \n| s!o#m$e%o^n\u0026e@realdomain.com  | Most public email providers only allow \"a-z\",\"0-9\",\".\",\"_\",\"-\",\"+\" before \"@\" |\n| someone@hotnail.com           | Common typo that can be blocked with the domain blocklist feature             |\n\n## Features\n\n- Works in both **Browser** and **Node.js** environments\n- Written in TypeScript with full type definitions\n- Zero dependencies\n- Customizable validation rules\n- DNS-over-HTTPS (DoH) support for browser environments\n- Custom MX resolver support for Node.js\n- Domain blocklist support\n- Detailed validation error reasons\n\n## Installation\n\n```shell\n# NPM\nnpm install email-validator-dns-provider-rules\n\n# Yarn\nyarn add email-validator-dns-provider-rules\n\n# pnpm\npnpm add email-validator-dns-provider-rules\n```\n\n## Basic Usage\n\n```js\nimport {validateEmail} from \"email-validator-dns-provider-rules\";\n\n// Basic validation\nconst result = await validateEmail('someone@gmail.com');\nif (!result.valid) {\n    console.log(`Email is invalid: ${result.reasonText}`);\n}\n```\n\n## API Reference\n\n### validateEmail(email, options)\n\nValidates an email address using DNS checks and provider-specific rules.\n\n**Parameters:**\n\n- `email` (string): The email address to validate\n- `options` (object, optional): Configuration options\n\n**Returns:**\n\n- Promise\u003cValidationResult\u003e: Object with validation results\n\n**ValidationResult Object:**\n\n- `valid` (boolean): Whether the email is valid\n- `reasonId` (number, optional): ID of the validation failure reason\n- `reasonText` (string, optional): Human-readable description of the validation failure\n\n### Options\n\n```typescript\ninterface ValidatorOptions {\n    blocklistDomains?: string[];      // Domains to block\n    dohProviderUrl?: string;          // Custom DNS-over-HTTPS provider URL\n    dohRetryAmount?: number;          // Number of retries for DNS queries\n    skipCache?: boolean;              // Skip the internal MX domain cache\n    mxResolver?: (domain: string) =\u003e Promise\u003cstring[] | false\u003e; // Custom MX resolver\n}\n```\n\n## Customizing Error Messages\n\nYou can provide your own error messages by mapping the reason IDs:\n\n```js\nconst customReasons = {\n    [INVALID_REASON_AMOUNT_OF_AT]: 'Email must contain exactly one @ symbol',\n    [INVALID_REASON_USERNAME_GENERAL_RULES]: 'Username contains invalid characters',\n    [INVALID_REASON_DOMAIN_GENERAL_RULES]: 'Domain name is invalid',\n    [INVALID_REASON_NO_DNS_MX_RECORDS]: 'Domain does not have mail server records',\n    [INVALID_REASON_DOMAIN_IN_BLOCKLIST]: 'This email domain is not allowed',\n    [INVALID_REASON_USERNAME_VENDOR_RULES]: 'Username does not meet provider requirements',\n    [INVALID_REASON_DOMAIN_POPULAR_TYPO]: 'Domain appears to be a typo (did you mean gmail.com?)',\n};\n\nconst result = await validateEmail('someone@gmail.com');\nif (!result.valid) {\n    console.log(`Email is invalid: ${customReasons[result.reasonId]}`);\n}\n```\n\n## Using Domain Blocklists\n\nYou can block specific domains:\n\n```js\nconst blockedDomains = [\n    'disposable-email.com',\n    'temporary-mail.org',\n    'hotnail.com'  // Common typo of hotmail.com\n];\n\nconst result = await validateEmail('user@disposable-email.com', {\n    blocklistDomains: blockedDomains\n});\n// result.valid will be false\n```\n\n## Custom DNS-over-HTTPS Provider\n\nYou can specify a custom DNS-over-HTTPS provider:\n\n```js\nconst result = await validateEmail('someone@gmail.com', {\n    dohProviderUrl: 'https://your-custom-doh-provider.com/dns-query'\n});\n```\n\n## Node.js Integration\n\nFor Node.js environments, you can use the native DNS module:\n\n```typescript\nimport {resolveMx} from 'dns/promises';\n\nasync function nodeResolver(emailDomain: string): Promise\u003cstring[] | false\u003e {\n    try {\n        const records = await resolveMx(emailDomain);\n        return records.map(rec =\u003e rec.exchange);\n    } catch (error) {\n        if (error.message.includes('ENOTFOUND')) {\n            return []; // Empty records treated as invalid\n        }\n        return false; // Other errors treated as \"can't determine\"\n    }\n}\n\nconst result = await validateEmail('someone@gmail.com', {\n    mxResolver: nodeResolver\n});\n```\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreinwald%2Femail-validator-dns-provider-rules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreinwald%2Femail-validator-dns-provider-rules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreinwald%2Femail-validator-dns-provider-rules/lists"}