Integrations · Email platforms

Validate your Amazon SES contact list

Check the contacts of your Amazon SES contact list and write each verdict into five keys of the contact's attributes: ev_status, ev_reason, ev_action, ev_checked_at and ev_address_hash (a hash of the address that was checked, never the address). The contact's other attributes, its topic preferences and its unsubscribe setting stay as they are. Nothing else in your account changes unless you ask for it: no contact is deleted or unsubscribed, and nothing is added to your suppression list. A script you run on your own computer does it, with your own keys.

Download it: email-validation-amazon-ses.zip holds the script amazon-ses.mjs and the MIT licence.

What you need

  • An API key of ours from the API keys page with Bulk lists (off by default: turn it on when you create the key).
  • An AWS account with SES in one Region, and that Region's name (for example us-east-1). Only the standard commercial Regions are supported: not the China Regions, AWS GovCloud or FIPS endpoints.
  • An IAM role there with the policy below, and the AWS CLI version 2 with a profile that assumes the role, to put a short-lived session of it in your shell (export-credentials is not in version 1).
  • For the free try, a second AWS account: SES allows one contact list per account.
  • Node 22.18 or later.

The script reads the AWS credentials only from the environment variables the AWS CLI's export-credentials sets, never from a profile or a credentials file. Our key goes only to our API, the AWS credentials only sign requests to your Region's SES and STS endpoints, and neither is written to a file or a log. The script prints counts and job ids, never a contact's address.

The IAM policy

Create a role with this policy, with REGION, ACCOUNT_ID and CONTACT_LIST_NAME replaced by yours. It is enough for a run and a dry run:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ReadAndWriteTheContactList",
      "Effect": "Allow",
      "Action": ["ses:ListContacts", "ses:GetContact", "ses:UpdateContact"],
      "Resource": "arn:aws:ses:REGION:ACCOUNT_ID:contact-list/CONTACT_LIST_NAME"
    }
  ]
}

Then put a session of the role in your shell, with the AWS CLI profile that assumes it:

eval "$(aws configure export-credentials --profile <profile that assumes the role> --format env)"

In Windows PowerShell: aws configure export-credentials --profile <profile> --format powershell | Invoke-Expression. A first run takes about three seconds per contact (see below), so for a large list set the role's and the profile's session duration as long as the role allows (up to 12 hours; a role assumed from another role session gets at most one hour).

Try it free first

A run checks, and charges for, every contact without a verdict, so never try it on your real list. Try it in a second AWS account, on one of our free test addresses (on a domain that receives no mail).

  1. In the test account, create the list Test with one contact, with an administrator profile of that account (the role can only read and update the list, and a role session already in your shell would win over --profile: run this first, or in a new shell). SES sends no confirmation or welcome email when a contact is created:

    aws sesv2 create-contact-list --profile <test account admin> --region us-east-1 --contact-list-name Test
    aws sesv2 create-contact --profile <test account admin> --region us-east-1 --contact-list-name Test --email-address no_mailbox@sandbox.email-validation.org
  2. Unzip the download, go into its folder and run the script on the test list, with a session of the test account's role in your shell:

    unzip email-validation-amazon-ses.zip
    cd email-validation-amazon-ses
    export EV_API_KEY=…
    node amazon-ses.mjs --aws-region us-east-1 --contact-list Test

    In Windows PowerShell (5.1 or 7):

    Expand-Archive email-validation-amazon-ses.zip -DestinationPath .
    cd email-validation-amazon-ses
    $env:EV_API_KEY = "…"
    node amazon-ses.mjs --aws-region us-east-1 --contact-list Test
  3. Look at the contact: aws sesv2 get-contact --region us-east-1 --contact-list-name Test --email-address no_mailbox@sandbox.email-validation.org. Its AttributesData holds ev_status invalid and ev_action remove. Checks of our test addresses are free.

Clean your list

With a session of your real account's role in the shell, see what a run would check (nothing is uploaded, paid or written), then check the list and write the verdicts:

node amazon-ses.mjs --aws-region us-east-1 --contact-list Newsletter --dry-run
node amazon-ses.mjs --aws-region us-east-1 --contact-list Newsletter

Each checked address uses one credit; unknown results, malformed addresses, duplicates and sandbox addresses are free. Contacts unsubscribed from all topics are left out unless you pass --include-unsubscribed. Contacts that already hold a verdict for their address are skipped unless you pass --revalidate; a contact whose attributes were copied from another address is checked again. --prefix crm_ writes the five keys under another prefix. Add --region eu to validate and store the list in the EU (our data residency; --aws-region is your SES Region).

Use the attributes in your own sends and exports. Filter on ev_action: spam traps and complainers are ev_status valid with ev_action remove.

How long it takes. SES allows one API request a second for every action except sending, and the script sends at most one a second. A first run makes about three requests per contact (a read, then for each contact it checks a fresh read and a write), so about three seconds per contact: roughly 8 hours for 10,000 contacts. Later runs read each contact once and write only the new ones. Exit codes: 0 done, 1 a write failed or the run stopped (run again to resume), 2 wrong arguments, 75 the bulk list was still running when the script stopped waiting (--wait-minutes, 240 by default).

Keep undeliverable addresses out of every send

Writing attributes does not change who receives mail. --suppress invalid (and --suppress disposable, one status per flag; never valid, unknown or catch_all) adds those addresses to your account-level suppression list, with the reason you name: --suppress-as bounce or --suppress-as complaint. This is off by default, and it reaches further than the list:

  • It blocks the address for every sender of the AWS account in that Region, not only mail to this list.
  • SES accepts a send to a suppressed address and does not deliver it, as long as your account's suppression settings include that reason. The script reads the settings and warns if they do not; it never changes them.
  • It needs an account out of the SES sandbox, and the role needs these actions as well:
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ReadAndWriteTheContactList",
      "Effect": "Allow",
      "Action": ["ses:ListContacts", "ses:GetContact", "ses:UpdateContact"],
      "Resource": "arn:aws:ses:REGION:ACCOUNT_ID:contact-list/CONTACT_LIST_NAME"
    },
    {
      "Sid": "ReadTheSuppressionSettings",
      "Effect": "Allow",
      "Action": ["ses:GetAccount"],
      "Resource": "*"
    },
    {
      "Sid": "AddToTheAccountLevelSuppressionList",
      "Effect": "Allow",
      "Action": ["ses:GetSuppressedDestination", "ses:PutSuppressedDestination"],
      "Resource": "*"
    }
  ]
}

A run with --suppress needs an undo file, where it records every address it adds:

node amazon-ses.mjs --aws-region us-east-1 --contact-list Newsletter --dry-run --suppress invalid --suppress-as bounce
node amazon-ses.mjs --aws-region us-east-1 --contact-list Newsletter --suppress invalid --suppress-as bounce --undo-file newsletter.undo.json

An address already on the suppression list is left exactly as it is. The undo file holds addresses (SES needs the exact address to remove an entry): it stays on your machine, readable by you only, and is never sent anywhere. Keep it while you may want to undo the run, then delete it. To undo, with a role that has the actions ses:GetSuppressedDestination and ses:DeleteSuppressedDestination:

node amazon-ses.mjs unsuppress --aws-region us-east-1 --undo-file newsletter.undo.json --dry-run
node amazon-ses.mjs unsuppress --aws-region us-east-1 --undo-file newsletter.undo.json

unsuppress removes only the entries this tool added that SES still holds as it left them: an entry updated since (a real bounce, for example) stays.

Re-runs and schedules

If a run stops (an expired session, no credits, an outage), start a new session and run the same command again from the same folder: the script keeps the bulk list's id in a small state file (ids only; no address, no key), resumes the same bulk list and never pays twice (within the 30 days a list is kept). A result it could not write is kept in a local file next to it (hashes, never an address) and written by the next run without a new check.

SES sends no event when a contact is added to a list, and a send with list management options to an address that is not on the list adds it. So check addresses at sign-up, with our API before they reach SES, and run the script on a schedule for the rest: each run checks only the contacts without a verdict for their address, and those still unknown.

More on Amazon SES

Updated · Maintained by: Email Validation LLC

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