Integrations · Email platforms
Check SMTP2GO recipients before you send
Check recipients before SMTP2GO sends to them. One module with no dependencies, copied into your own server: before each send it checks every address in the message's to, cc and bcc and sends the message to SMTP2GO without the ones that cannot receive mail. By default only a definite invalid is set aside; everything else is sent as before. SMTP2GO has no hook that runs before a send, so the check runs in your code, just before you call SMTP2GO's API.
Download it: email-validation-smtp2go.zip holds the module as TypeScript (email-validation-smtp2go.ts) and as JavaScript (email-validation-smtp2go.mjs), and the MIT licence.
What you need
- An API key of ours from the API keys page with Validate addresses (on by default).
- An SMTP2GO API key, made in SMTP2GO under Sending → API Keys. Its permissions must allow
/email/sendforguard.send, and also/suppression/addif you turn on the optional suppression below. - Your server's code, in anything with
fetchand Web Crypto (Node 22 or later, Bun, Deno, Cloudflare Workers). Copyemail-validation-smtp2go.tsinto a TypeScript project, oremail-validation-smtp2go.mjsinto a JavaScript one. Import the.tsfile with its extension under Node 22.18 or later, Deno or Bun; under a bundler, leave the extension out.
Our key goes only to our API. The SMTP2GO key goes only in the X-Smtp2go-Api-Key header, never in a body, to the SMTP2GO host you pick by name: 'global' (the default, api.smtp2go.com), 'us', 'eu' or 'au'. Redirects are never followed, and the module logs nothing.
Before a send
Make the guard once per process, not per send: it remembers answers between sends.
import { createSmtp2goGuard } from './email-validation-smtp2go.ts'; // .mjs in JavaScript
const guard = createSmtp2goGuard({
apiKey: process.env.EV_API_KEY, // region: 'eu' here checks in the EU
smtp2go: { apiKey: process.env.SMTP2GO_API_KEY }, // SMTP2GO's host: region 'global' (default), 'us', 'eu' or 'au'
});
const result = await guard.send({
sender: 'Acme <hello@acme.example>',
to: [`${user.name} <${user.email}>`],
subject: 'Welcome',
html_body: '<p>Welcome!</p>',
});
// result: { accepted, emailId, requestId, succeeded, failed, failures, precheck: { blocked, … } }guard.send takes the body you would post to SMTP2GO's /v3/email/send. Each recipient is a "Name <address>" string or a bare address; the address in angle brackets is the one checked, and only the blocked recipients are taken out. A message whose every to is blocked is not sent (accepted: false). SMTP2GO answers 200 even when some recipients failed, so read failed and failures (SMTP2GO sends them only without fastaccept).
Keep your own SMTP2GO client? guard.checkRecipients(message) does the check alone: send its message yourself when empty is false. guard.check(address) checks one address, for a sign-up form, or for the recipients of a MIME message (/v3/email/mime), which the module does not rewrite: leave out those with blocked: true before you build it.
Try it free first
Check one of our free test addresses (on a domain that receives no mail) without sending anything:
const guard = createSmtp2goGuard({ apiKey: process.env.EV_API_KEY });
const { empty, blocked } = await guard.checkRecipients({
sender: 'Acme <hello@acme.example>',
to: ['no_mailbox@sandbox.email-validation.org'],
subject: 'Test',
text_body: 'Hi',
});
console.log(empty, blocked); // true [ { field: 'to', recipient: 'no_mailbox@…', status: 'invalid', reason: 'no_mailbox' } ]Checks of our test addresses are free. Never send to them, or to any address you made up, through SMTP2GO: a send to an address that cannot receive mail bounces and hurts your sending reputation.
How it decides
- What is blocked.
invalidby default;blockalso takesdisposable,catch_allandunknown(validcannot be blocked). Anunknownthat comes from our side (a timeout or our own failure) is never blocked. - It fails open. No key, a timeout (6 seconds per check by default,
timeoutMs), a network error, a rate limit or any error answer keeps the recipient, so a problem on our side never stops your mail. Checks are never retried. A value that is no address (a link, a name) is kept and never sent to our API. Give each recipient its own entry: in a string holding two addresses only the last one in angle brackets is checked, and the whole entry goes with it. - Bounded time. All the checks of one call share
budgetMs(10 seconds by default); a recipient not checked by then is kept. When our API answers with a rate limit, the guard waits before it checks again, and meanwhile keeps recipients. - Verdicts are remembered. A definite answer is remembered for 30 days (
rememberDays) under a hash of the address, never the address, up to 10,000 per guard;store(Redis, Workers KV, a database) shares them between processes. A later timeout orunknownnever clears an earlier verdict. - Credits. Each check uses one credit (
unknownresults, malformed and sandbox addresses are free); a remembered answer costs nothing.region: 'eu'checks in the EU, athttps://api-eu.email-validation.org. - SMTP2GO's errors throw an
Smtp2goErrorwith acode, the HTTPstatusand SMTP2GO's own code (smtp2goCode), and never hold a key or an address. Sends are never retried.
Add invalid addresses to your suppressions (optional)
smtp2go: { apiKey, suppress: true } also adds each recipient blocked as a definite invalid to your SMTP2GO suppressions, so SMTP2GO skips that address from then on wherever the send comes from (SMTP relay, other code, the dashboard). It is off by default and never done for a disposable, catch-all or unknown address or one that got no answer. guard.send posts the mail first, then the additions, one address a request, so they never delay it. A failed addition is reported in precheck.suppressed.error, never retried, and pauses further additions for a while. To undo an entry, remove it from your suppressions in SMTP2GO.