Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

mailcheck

> 编程语言
Open source

Reduce misspelled email addresses in your web apps.

7.9K stars0 likes3 views
WebsiteGitHub

About

Reduce misspelled email addresses in your web apps.

Mailcheck 2.0

Mailcheck suggests a likely email domain when someone makes a typo. It is a small JavaScript library with an optional jQuery plugin. Mailcheck originated at Kicksend.

[email protected]  →  [email protected]
sample@gmail      →  [email protected]

Mailcheck is a typo suggester, not an email validator or a deliverability check. Show a suggestion; do not silently replace an address or block someone from continuing.

Behavior

  • The established JavaScript API remains available: the same methods, options, callbacks, return values, browser global, and jQuery plugin.
  • Bundled TypeScript declarations require no separate @types/mailcheck package.
  • Recognized modern domain endings such as .ai, .io, .app, and .co are not rewritten merely because another ending is close.
  • Provider defaults include Proton, HEY, Fastmail, and Tuta.
  • An exact, unambiguous configured domain with a missing ending can be completed: sample@gmail can suggest [email protected].
  • Equally close candidates produce no suggestion rather than depending on list order.
  • Local-part case and repeated literal percent signs are preserved.
  • Mailcheck has no runtime dependencies and makes no network requests.

Install

npm

bash
npm install mailcheck

Browser

Load the browser build before calling Mailcheck.run:

xml
<script src="/path/to/mailcheck.min.js"></script>

Use without jQuery

Call Mailcheck.run() when the person leaves the email field. Render the suggestion as text, never as HTML.

xml
<input id="email" type="email" autocomplete="email">
<p id="suggestion" aria-live="polite"></p>

<script src="/path/to/mailcheck.min.js"></script>
<script>
  var email = document.getElementById('email');
  var output = document.getElementById('suggestion');

  email.addEventListener('blur', function () {
    Mailcheck.run({
      email: email.value,
      suggested: function (suggestion) {
        output.textContent = 'Did you mean ' + suggestion.full + '?';
      },
      empty: function () {
        output.textContent = '';
      }
    });
  });
</script>

run() returns the suggestion when no callbacks are supplied:

javascript
var suggestion = Mailcheck.run({ email: '[email protected]' });
// { address: 'sample', domain: 'gmail.com', full: '[email protected]' }
// or undefined when there is no suggestion

Mailcheck does not alter the field value. Let the person choose whether to change it.

Use with jQuery

Load jQuery first, then Mailcheck:

xml
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="/path/to/mailcheck.min.js"></script>
javascript
$('#email').on('blur', function () {
  $(this).mailcheck({
    suggested: function (element, suggestion) {
      $('#suggestion').text('Did you mean ' + suggestion.full + '?');
    },
    empty: function () {
      $('#suggestion').empty();
    }
  });
});

The plugin passes the jQuery element first and the suggestion second. It returns void.

Node.js and TypeScript

CommonJS

javascript
var Mailcheck = require('mailcheck');
var suggestion = Mailcheck.run({ email: '[email protected]' });

ESM and TypeScript

typescript
import Mailcheck from 'mailcheck';
import type { Suggestion } from 'mailcheck';

const suggestion: Suggestion | undefined = Mailcheck.run({
  email: '[email protected]'
});

The default import uses CommonJS interoperability, supported by Node ESM and TypeScript with esModuleInterop. For CommonJS TypeScript, use:

typescript
import Mailcheck = require('mailcheck');

To use the existing jQuery plugin types alongside your normal jQuery types:

typescript
import type {} from 'mailcheck/jquery';

This adds declarations only. Load the jQuery and Mailcheck runtime scripts as usual.

Customize domain suggestions

Pass lowercase lists to replace the relevant defaults:

javascript
Mailcheck.run({
  email: '[email protected]',
  domains: ['acme.com', 'example.org'],
  secondLevelDomains: ['acme'],
  topLevelDomains: ['com', 'org']
});

Or extend the defaults:

javascript
Mailcheck.defaultDomains.push('acme.com');
Mailcheck.defaultSecondLevelDomains.push('acme');
Mailcheck.defaultTopLevelDomains.push('org');

domains, secondLevelDomains, and topLevelDomains replace their respective defaults when passed to run(). The public topLevelDomains list contains correction targets; Mailcheck’s internal recognition of real domain endings is not another option to configure.

You can provide a custom distance function:

javascript
Mailcheck.run({
  email: '[email protected]',
  distanceFunction: function (left, right) {
    return Mailcheck.sift4Distance(left, right);
  }
});

Matching rules

Mailcheck deliberately abstains when confidence is low:

  • Valid recognized endings remain unchanged. [email protected] receives no suggestion because .co is real.
  • A missing ending is completed only from one exact full-domain target already in domains.
  • Partial names, unknown domains, malformed layouts, Unicode/punycode domains, and ambiguous matches receive no suggestion.
  • A threshold of 0 means exact matches only.
  • Mailcheck does not prove that an address exists, accepts mail, or belongs to a person.

The lower-level Mailcheck.suggest() accepts explicit correction lists and returns a suggestion object or false:

javascript
Mailcheck.suggest(
  '[email protected]',
  ['gmail.com'],
  ['gmail'],
  ['com'],
  Mailcheck.sift4Distance
);

Render suggestions safely

run() retains the legacy encodeEmail() behavior. That encoding is not a general HTML sanitizer. Use textContent, jQuery .text(), or your framework’s escaped text rendering when displaying suggestions. Do not insert user input with innerHTML.

Test and build

Install the locked development dependencies without lifecycle scripts:

bash
npm ci --ignore-scripts --no-audit --no-fund
npx --no-install playwright install chromium firefox webkit
npm run test:ci

Useful commands:

Command Purpose
npm run test:ci Run the full test suite.
npm test Run core, regression, and release-packaging tests.
npm run test:types Check TypeScript declarations.
npm run test:package Test a packed archive as a separate consumer.
npm run test:e2e Run browser tests in Chromium, Firefox, and WebKit.
npm run build Regenerate src/mailcheck.min.js.
npm run build:check Verify that the minified build is current.
npm run test:release Test the local release archive workflow.

When changing behavior, add a focused regression test and regenerate the minified build. The test suite uses synthetic addresses and local test resources only.

Release archives

bash
./cut_release.sh VERSION
./cut_release.sh VERSION --dry-run

The command writes Releases/mailcheck-VERSION.tgz and refuses to overwrite an existing archive. It creates the versioned metadata and minified build in a temporary copy, leaving checkout version files unchanged. The archive includes only runtime files, declarations, manifests, this README, and the license.

Organizations that have used Mailcheck

Organizations that have used Mailcheck include:

  • Dropbox
  • Hack Design
  • Kicksend
  • Kickstarter
  • Khan Academy
  • Lyft
  • Minecraft
  • SB Nation
  • The Verge
  • GOV.UK Pay
  • Jo

People

  • Derrick Ko — original author
  • Wei Lu — maintainer
  • Pradeep Elankumaran — maintainer (GitHub)

Mailcheck has also benefited from its wider contributor community; see the contributors page for the complete history.

Contributing

  • Preserve the public API and module entry points.
  • Prefer no suggestion over a wrong one.
  • Do not silently rewrite a person’s address.
  • Keep new behavior covered in the relevant core, package, type, or browser tests.
  • Run npm run build and npm run test:ci before proposing a change.

See README-1.x.md for the preserved pre-2.0 README and historical links.

License

MIT. See LICENSE.

Issues· 4 open

View all issuesOpen on GitHub
  • #194

    Offer to help maintain Mailcheck

    Updated Sep 19, 2026
  • #147

    version 1.1.2 has not been published to npm

    Updated Sep 14, 2026
  • #176

    Error: 'default' is not exported by node_modules/mailcheck/src/mailcheck.js

    Updated Oct 23, 2022

> Tags

JavaScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedOct 1, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言