Integrations · CRM
Validate your Capsule contacts
Check the email addresses of your Capsule CRM contacts (people and organisations) and write each result into four custom fields, so a filtered list can leave out the addresses you should not mail. A script you run on your own computer reads every contact, checks the addresses (up to 50 one by one, more as one bulk list) and writes the results back. It never deletes, merges or changes a contact's address. Download it: email-validation-capsule.zip holds capsule.mjs (the script) and the MIT licence.
What you need
- A computer with Node 22.18 or later. Nothing to install: the script has no dependencies.
- An API key of ours from the API keys page with Validate addresses, and the permission Bulk lists (off by default: turn it on when you create the key) for more than 50 contacts.
- A Capsule personal access token: in Capsule, My Preferences → API Authentication Tokens. The token acts as your user, so that user needs to see and edit every contact and, for the first run, be an administrator: the first run creates the four custom fields.
Try it free first
Every definite result uses one credit (unknown results, malformed and test addresses are free), so try it on a Capsule account that holds only test contacts (Capsule offers a 14-day trial), never on your real ones. Give one test contact the address no_mailbox@sandbox.email-validation.org (sandbox checks are free; that domain receives no mail, so send it nothing), then:
cd email-validation-capsule # the unzipped folder
export CAPSULE_TOKEN=… EV_API_KEY=…
node capsule.mjs --dry-run # creates nothing, checks nothing, writes nothing: only counts
node capsule.mjs # creates the four fields if missing, checks and writesIn Windows PowerShell (5.1 or 7):
cd email-validation-capsule # the unzipped folder
$env:CAPSULE_TOKEN = "…"; $env:EV_API_KEY = "…"
node capsule.mjs --dry-run # creates nothing, checks nothing, writes nothing: only counts
node capsule.mjs # creates the four fields if missing, checks and writesThe contact's ev_status field says invalid and ev_reason says no_mailbox. Run it once more: it reports nothing to check, because every result was written. Then delete the test contact.
Run it
node capsule.mjs --dry-run # how many contacts would be checked; free
node capsule.mjs # checks and writesUp to 50 addresses are checked one by one; more go out as one bulk list. A contact is checked by its first email address (Capsule marks none as primary), and one whose address already has a result is skipped (an unknown result is checked again), so a daily run checks only new and changed addresses. If a run stops, run the same command again from the same folder: it resumes the same bulk list and never pays twice (within the 30 days a list is kept). The state file (.ev-capsule-<subdomain>.json, named by your account's Capsule address) lives in that folder. Before you rename that address, let a run that ended with exit code 75 finish (run it again until it exits 0): a run after the rename starts a new list. It prints ids and counts, never an address or a token.
Capsule allows 4,000 requests an hour for each user and asks for about a second between requests, so the script sends one request a second. When Capsule says the limit is reached, it waits until Capsule's reset time, up to a minute per wait; if Capsule still refuses, it stops and the same command resumes. A run sends one request for every 100 contacts it reads and two for every contact it writes.
Options:
--region eu: checked in the EU, lists and results kept there, with the same key.--revalidate: check again addresses that already have a result.--state FILE: a state file of your own choosing.CAPSULE_TIMEOUT_MS: how long one Capsule request may take, in milliseconds (1 to 60000; default 30000).
Exit codes: 0 done; 1 a write failed or the run stopped (run it again: nothing is paid twice); 2 wrong options; 75 the bulk list was still being checked when the script stopped waiting (run it again later to collect it).
What it writes
Four custom fields of type Text for people and organisations, created by the first run when they are missing (an administrator can create them in Capsule first, with exactly these names):
| Field | Holds |
|---|---|
ev_status | valid, invalid, catch_all, unknown or disposable |
ev_reason | the reason, for example no_mailbox or accepted |
ev_checked_at | when it was checked |
ev_address_hash | a hash of the address the result belongs to, so a changed address is checked again |
A field of one of these names that is not a Text field, sits on a tag, or is there twice stops the run before anything is checked. Spam traps and complainers are valid with a warning reason: see what each status means. Each result is written by contact id, and only while the contact still holds the address that was checked; the write holds only these four values, and Capsule changes only what a write holds, so the contact's names, addresses, tags and other fields stay as they are. A result that could not be written is kept in a file next to the state file and written by the next run without a new check.
A contact filter on ev_status is invalid or disposable finds the contacts to leave out of your mailings.
End the access
Delete the token in Capsule (My Preferences → API Authentication Tokens) and our key on the API keys page. The four fields stay on your contacts until you delete them in Capsule.