Integrations · Sales outreach
Clean Mailshake recipients before you send
Check the recipients of a Mailshake campaign before you send, as one bulk list, and get each recipient's status in a result file on your computer; when you ask for it, the script also pauses the recipients you should not mail. It tells you what it will cost and asks before it spends anything. It never deletes a recipient, never unsubscribes one, and never changes a campaign, a lead or any other data. Download it: email-validation-mailshake.zip holds mailshake.mjs, one file, and the MIT licence.
What you need
- Node 22.18 or later. Nothing to install: the script has no dependencies.
- An API key of ours from the API keys page with the permission Bulk lists (off by default: turn it on when you create the key). With Read balance and usage too, the script shows your balance before it asks.
- A Mailshake API key: in Mailshake, Extensions → API. Mailshake answers its API only for a team with an active, paid subscription (the script says so when it does not); check with Mailshake which plans include it. Keep the key like a password.
Run it
cd email-validation-mailshake # the unzipped folder
export EV_API_KEY=… MAILSHAKE_API_KEY=…
node mailshake.mjs --lists # your campaigns: id, recipients (with --counts), state, name
node mailshake.mjs --campaign <id> --dry-run # what it would check and the most it would cost; spends nothing
node mailshake.mjs --campaign <id> # asks, then checks and writes the result file
node mailshake.mjs --campaign <id> --pause # the same, and pauses the recipients not to mail
node mailshake.mjs --campaign <id> --yes # without asking (for a scheduled run)Before it spends, the script shows the recipients it will check, the distinct addresses, the most credits it will use (one per distinct address; unknown results, duplicates and malformed addresses are free) and your balance, and asks you to confirm. With --yes it goes on without asking; without a terminal and without --yes it stops before spending.
It checks the recipients that have an address and are not paused (--all-recipients checks paused ones too), and skips the ones the result file already has a status for (--revalidate checks them again). --region eu checks and keeps the list in the EU, with the same key.
The result file
Mailshake's API cannot store a value on a recipient, so the results go into a file in the folder you run the script from, mailshake-results-<campaign id>.csv (or --results FILE), one row per recipient:
| Column | Value |
|---|---|
recipient_id | Mailshake's recipient id |
email_address | the address as Mailshake holds it |
email_validation_status | valid, invalid, catch_all, unknown or disposable (statuses) |
email_validation_action | send, send_with_caution, remove or retry_later |
email_validation_reason | why, for example no_mailbox |
email_validation_checked_at | when the result was written, in UTC |
paused_by_check | yes when the script paused the recipient |
Leave out the recipients whose action is remove: spam traps and complainers are valid with the action remove. The file holds your campaign's addresses, so keep it as private as the campaign (the script writes it readable by you alone and never prints it). The next run reads it, so a monthly run checks only the recipients that are not in it yet, such as new ones, and those it holds as unknown or with an address that changed since.
Pausing
With --pause (off unless you add it), each recipient whose action is remove is paused in the campaign, so Mailshake sends it nothing more. Unpausing it in Mailshake undoes that, and the script never pauses a recipient again that you unpaused. Before each pause it reads the recipient again and pauses it only while its address is still the one checked. A pause Mailshake refuses stays unpaused in the file, and the next run with --pause tries it again.
You can run once without --pause, look at the file, then run again with --pause: the recipients the file marks remove are paused with no new check and no credits.
Mailshake's quota
Mailshake counts quota units per hour for your whole team, shared with every other tool using its API. Reading a campaign's recipients and each pause use some of them; the script prints how many units each run used. When the units run out, it waits until Mailshake says they are back (at most --quota-wait-minutes, 65 by default), then goes on; when they come back later than that, it stops and tells you when to run it again, without paying twice. --rate N sets how many Mailshake requests it sends a second (2 by default, at most 10).
Run it again
Run the same command again after any stop (no credits, a closed laptop, Mailshake's quota, the bulk list still running): it resumes the same bulk list and never pays twice (within the 30 days a list is kept). Run it from the same folder each time (or pass the same --state FILE): the file it keeps there holds the bulk list it is working on, never an address or a key. When every recipient is recorded, that file is removed, and the next run checks only recipients that are not in the result file yet (or are there as unknown, or with another address).
Exit codes: 0 done (or you answered no), 1 the run stopped or a pause failed (run it again), 2 wrong arguments, 75 the bulk list was still running when the script stopped waiting (run it again later).
The script prints counts, recipient ids, job ids and the campaign's name, never an address or a key.