Integrations · Email platforms

Check Postmark recipients before you send

Check recipients before Postmark 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 Postmark without the ones that cannot receive mail. By default only a definite invalid is taken out; everything else is sent as before.

Download it: email-validation-postmark.zip holds the module as TypeScript (email-validation-postmark.ts) and as JavaScript (email-validation-postmark.mjs), and the MIT licence.

What you need

  • An API key of ours from the API keys page with Validate addresses (on by default).
  • Your Postmark server's API token, from the server's API Tokens tab in Postmark.
  • Your server's code, in anything with fetch and Web Crypto (Node 22 or later, Bun, Deno, Cloudflare Workers). Copy email-validation-postmark.ts into a TypeScript project, or email-validation-postmark.mjs into a JavaScript one. Import the .ts file 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 Postmark server token only to api.postmarkapp.com, 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 { createPostmarkGuard } from './email-validation-postmark.ts'; // .mjs in JavaScript

const guard = createPostmarkGuard({
  apiKey: process.env.EV_API_KEY,
  postmark: { serverToken: process.env.POSTMARK_SERVER_TOKEN },
});

const { submitted, response, precheck } = await guard.sendEmail({
  From: 'hello@acme.example',
  To: `${user.name} <${user.email}>`,
  Subject: 'Welcome',
  TextBody: 'Hi!',
  MessageStream: 'outbound',
});
// precheck.blocked: the entries taken out, e.g. [{ field: 'To', entry: '…', status: 'invalid', reason: 'no_mailbox' }]
// response: Postmark's answer, or null when the message was held (submitted: false)

sendEmailWithTemplate, sendEmailBatch and sendEmailBatchWithTemplates do the same for Postmark's other three send calls. A batch keeps your order; a held message in it is left out and answers submitted: false, and Postmark answers each sent message with its own ErrorCode (0 is accepted).

Only the blocked entries are taken out of a field; a field with nothing blocked is sent exactly as written, and every other field of the message is sent as is. A message is held (not sent) when every recipient is blocked, or every To is: Postmark needs a To, and the guard never moves a Cc there.

Keep your own Postmark client? guard.precheckMessage(message) does the check alone and answers message (a copy to send, or null when it is held) and blocked. guard.check(address) checks one address, for a sign-up form.

Try it free first

Check one of our free test addresses (on a domain that receives no mail) without sending anything:

const guard = createPostmarkGuard({ apiKey: process.env.EV_API_KEY });
const { message, held, blocked } = await guard.precheckMessage({
  From: 'hello@acme.example',
  To: 'no_mailbox@sandbox.email-validation.org',
  Subject: 'Test',
});
console.log(message, held, blocked); // null 'all_blocked' [ { field: 'To', status: 'invalid', reason: 'no_mailbox', … } ]

Checks of our test addresses are free. Never send to them, or to any address you made up, through Postmark: a send to an address that cannot receive mail bounces and hurts your sending reputation.

How it decides

  • What is blocked. invalid by default; block: ['invalid', 'disposable'] also blocks disposable addresses (status disposable, or any answer that marks the address disposable). Every other catch_all and unknown, and every address that got no answer, is always sent.
  • 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.
  • Verdicts are remembered. A verdict is remembered in the process under a hash of the address, never the address, so that address is not checked again; an unknown or a failed check is not remembered and is asked again. store (KV, Redis, a database with an expiry) shares verdicts between processes.
  • Credits. Each check uses one credit (unknown results, malformed and sandbox addresses are free); a remembered answer costs nothing. region: 'eu' checks in the EU, at https://api-eu.email-validation.org.
  • Postmark's errors throw a PostmarkError with a code, the HTTP status and Postmark's postmarkErrorCode, and never hold a key or an address. Sends are never retried.

Suppress invalid addresses on the stream (optional)

postmark: { serverToken, suppress: true } also adds each recipient blocked as a definite invalid to the suppression list of its message's stream (MessageStream, or outbound). Postmark then refuses that address on the stream, also for sends that do not go through the guard, until you remove it in Postmark. It is off by default, never done for a disposable or unknown address or one that got no answer, and a failure never stops the send. Suppressions are per stream: a transactional stream's list does not cover a broadcast stream.

Postmark's SMTP sending is not covered by the guard: check the recipients with guard.check before you hand a message to SMTP.

More on Postmark

Updated · Maintained by: Email Validation LLC

Need help? Contact support, or ask the help chat. Something wrong or missing on this page? Tell us