Integrations · Email platforms

Check Resend recipients before you send

Check recipients before Resend sends to them, and your contacts before a Broadcast. One module with no dependencies, copied into your own server: before each send it checks the email's to, cc and bcc addresses and hands back the email without the ones that cannot receive mail. A small tool does the same for your Resend contacts: it reports the ones to set aside and, when you ask, marks them unsubscribed so Broadcasts skip them. By default only a definite invalid is set aside; everything else is sent as before.

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

What you need

  • An API key of ours from the API keys page with Validate addresses (on by default).
  • For the module: your server's code, in anything with fetch (Node, Bun, Deno, Cloudflare Workers). Copy email-validation-resend.ts into a TypeScript project, or email-validation-resend.mjs into a JavaScript one.
  • For the contacts tool: Node 22.18 or later, and a Resend API key with Full access (a Sending access key can only send, so it cannot read contacts).

Our key goes only to our API, the Resend key only to api.resend.com. The module logs nothing.

Before a send

import { Resend } from 'resend';
import { precheckEmail } from './email-validation-resend';

const resend = new Resend(process.env.RESEND_API_KEY);
const { email, blocked } = await precheckEmail(
  { from: 'Acme <hello@acme.example>', to: [signup.email], subject: 'Welcome', html },
  { apiKey: process.env.EV_API_KEY },
);
if (email) await resend.emails.send(email);
// blocked: [{ field: 'to', recipient, status: 'invalid', reason: 'no_mailbox' }, …]

precheckEmail checks each distinct address of to, cc and bcc once (the address inside Name <…> too) and answers the email without the blocked recipients, or null when no to recipient is left: then send nothing. When nothing is blocked you get the same object back. The sender and reply-to addresses are never checked. For resend.batch.send, precheckBatch(emails, options) answers send (the emails to send, in their order) and dropped (the positions of the emails whose every to recipient was 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. Each check uses one credit, every time you call it (unknown results, malformed and sandbox addresses are free). block sets aside more statuses, for example block: ['invalid', 'disposable']; valid cannot be blocked. region: 'eu' checks in the EU.

Try it free first

Check a sandbox address without sending anything:

const { email, blocked } = await precheckEmail(
  { from: 'Acme <hello@acme.example>', to: ['no_mailbox@sandbox.email-validation.org'], subject: 'Test' },
  { apiKey: process.env.EV_API_KEY },
);
console.log(email, blocked); // null, and the recipient blocked as invalid (no_mailbox)

Sandbox checks are free, and that domain receives no mail: never send to it, or to any address you made up, through Resend. A send to an address that cannot receive mail bounces and counts against your sending reputation.

Your contacts, before a Broadcast

In Resend, make a segment holding one test contact whose email is no_mailbox@sandbox.email-validation.org, and do not send a Broadcast until you have deleted it (a Broadcast to any segment that holds it would send to it). Then:

cd email-validation-resend                  # the unzipped folder
export EV_API_KEY=…  RESEND_API_KEY=…
node resend.mjs --segment <the test segment's id>            # report only: changes nothing
node resend.mjs --segment <the test segment's id> --apply    # marks the test contact unsubscribed

Then delete the test contact. On your real contacts, a report checks every distinct subscribed address (each one credit), so it costs the same as a clean: run it once with --apply when you are ready, all contacts or one --segment.

With --apply, the tool reads each blocked contact again and marks it unsubscribed only when its address is still the one checked and it is still subscribed. Resend's unsubscribe is for the whole account: the contact leaves every Broadcast, also when you name a segment. It never deletes a contact and never subscribes one again. --block invalid,disposable sets aside more statuses, --region eu checks in the EU, and cleanContacts(options) does the same from your own code.

Resend's rate limit is shared by every key of your team (10 requests a second by default), so the tool spaces its Resend calls 250 ms apart. If Resend refuses part way, run the same command again: contacts already marked are skipped, and the others are checked (and charged) again.

Exit codes: 0 done, 1 Resend refused or failed, or our API stopped the checks (a key, credits, daily cap or rate limit answer), 2 wrong arguments or a missing key. The report prints the blocked addresses to your terminal only; nothing is written to a file.

More on Resend

Updated · Maintained by: Email Validation LLC

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