Integrations · Mail servers and panels
Check outgoing recipients in Exim and cPanel
A recipe for Exim mail servers that checks the recipients of the mail your users send out, while it is being submitted. By default it only logs each result: it adds no header and never refuses a recipient unless you turn that on. When a check cannot be made in time, or the API answers with an error, the recipient is unchecked and the mail goes out as usual.
It has two parts: ev-helper, a small daemon (Python 3 standard library, no packages) that Exim asks over a Unix socket, and three short files for your Exim configuration. Download them as one zip: ev-exim-1.0.0.zip, which unpacks into a folder ev-exim/.
What gets checked
Only outbound mail: the sender authenticated, or connects from a host in relay_from_hosts, and the recipient's domain is not one of your local_domains or relay_to_domains. Mail arriving for your own mailboxes is never checked, and nor are messages submitted with the sendmail command.
Set it up
Create an API key for the server on the API keys page with the permission Validate addresses and a daily credit cap.
Put the key in
/etc/ev-helper/api-keywithout showing it: as root in bash, runinstall -d -m 0755 /etc/ev-helperand(umask 077; read -rs -p 'API key: ' key && printf '%s\n' "$key" > /etc/ev-helper/api-key; echo), then paste the key at the prompt (it is not shown and stays out of your shell history). Then copyev_helper.pyto/usr/local/lib/ev-helper/andev-helper.confto/etc/ev-helper/, then runpython3 -I /usr/local/lib/ev-helper/ev_helper.py --check-config.Install
ev-helper.socketandev-helper.servicein/etc/systemd/system/, setSocketGroup=to the group Exim runs as, and runsystemctl enable --now ev-helper.socket. The key stays readable by root only: systemd hands the helper its own copy. That needs systemd 247 or later; on an older systemd (RHEL and AlmaLinux 8 have 239), create a system userev-helperthat owns the key file, and inev-helper.servicereplaceLoadCredential=andDynamicUser=withUser=ev-helper.Copy the three files in the zip's
exim/folder to/etc/exim/ev/(Debian and Ubuntu:/etc/exim4/ev/, and use that path in the lines below), then add the three include lines to your Exim configuration:# main part, before "begin acl" .include /etc/exim/ev/ev-macros.conf # first lines of the RCPT ACL (acl_check_rcpt:), before any accept for authenticated or relay hosts .include /etc/exim/ev/ev-rcpt.acl # the DATA ACL (acl_check_data:); needed only for the optional header .include /etc/exim/ev/ev-data.aclCheck the configuration with
exim -bV, try a test session withexim -bh 127.0.0.1andRCPT TO:<no_mailbox@sandbox.email-validation.org>, then reload Exim.
Test addresses on sandbox.email-validation.org return the result their name says, cost nothing and contact no mail server, so you can see every mode work before you spend a credit.
cPanel and WHM
cPanel rebuilds Exim's configuration on every save and update, so on a cPanel server use the WHM plugin instead of the steps above. As root, in the unpacked ev-exim/ folder of ev-exim-1.0.0.zip: sh whm/install.sh. Then open WHM > Plugins > email-validation.org recipient checks, paste the key and choose Save and test (one free check of a test address). The page sets the mode (log only, the default, or refuse) and the API host, and shows the helper's status and today's counts, never an address.
The plugin adds the statements through cPanel's own places for Exim customisations (the Advanced Editor's main section and a custom RCPT ACL block), which are built to survive rebuilds and cPanel updates. It checks every change before Exim restarts and puts everything back if a step fails. sh whm/uninstall.sh takes the statements out of Exim first, then removes the helper. A failing check never stops mail: when the API or the helper is slow or down, recipients go out unchecked.
Try it on a test server before a production one.
Modes
| Mode | Set | What happens |
|---|---|---|
| Log (default) | nothing | a log line per checked recipient (ev-check rcpt=<…> status=invalid reason=no_mailbox source=api) |
| Tag | EV_HEADER = yes | as log, and the header X-EV-Recipient-Status on the message |
| Reject | EV_REJECT_MODE = yes | as log, and a recipient whose result is invalid with a reason in EV_REJECT_REASONS is refused |
The switches are on only for a true value such as yes; no, or leaving the line out, keeps them off.
A header added while recipients are checked belongs to the whole message, so it cannot say which recipient got which result: the log line does that. The optional header lists the statuses of the checked recipients, each once (valid, invalid), without addresses or counts. But every copy of the message carries it, local deliveries and Bcc recipients included, so it tells each recipient that the message also went to checked outside recipients and what their statuses were, even ones they cannot see. Use it only for your own routers or system filter, and remove it with headers_remove = X-EV-Recipient-Status in every transport, local ones too.
Reject mode is off by default, because a refused recipient is mail that does not go out and no check is perfect. It refuses only invalid results with the reasons you list (by default no_mailbox, no_dns, no_inbound_mail and unroutable), never unknown or unchecked ones, and the other recipients still get the message. Your user sees the refusal at once in their mail program instead of a bounce later. Turn it on when protecting your server's sending reputation matters more: mail to addresses that do not exist is what mailbox providers count against a server.
What it costs
Each check the helper sends costs at most 1 credit, as with any validation request; unknown results, errors, malformed addresses and test addresses are free. A check of an address checked before also costs 1 credit (repeat checks), so the helper keeps its own cache, and an answer from it costs nothing. Credits come in one-time packs, as little as $0.15 per 1,000 with the 50,000,000-credit pack (smaller packs cost more per credit), and new accounts get 500 free credits (100 when you sign up with a free email provider such as Gmail, Outlook or Yahoo, another personal mailbox such as a paid one like Fastmail or one from your internet provider, or an address from a relay or alias service).
Four limits bound what it spends:
- The cache: each result is reused until its time is up (30 days for
validanddisposable, 7 days forinvalidandcatch_all, 30 minutes forunknown). Anunknownthat only says our side could not finish the check is not kept. - Per sender: 30 checks at once, then 120 an hour, for each sender (the authenticated user, else the relay host's IP address). Past that, their recipients go out unchecked, so a hijacked account spends at most that much of your credits before its checks stop.
- Per day: at most 1,000 checks a day (UTC) for all senders together, kept across restarts; once it is used up, every recipient goes out unchecked until the next day.
- The key's daily credit cap, which the API enforces whatever happens on your server.
Every limit can be changed in /etc/ev-helper/ev-helper.conf.
Privacy
The helper sends each outside recipient's address, and nothing else of the message, in the body of a POST to https://api.email-validation.org (or https://api-eu.email-validation.org with region = eu, see EU data residency), never in a URL and to no other host. Its cache holds a keyed hash of each address, never the address, and its log never holds the API key or an address. Exim's own log line names the recipient, like Exim's delivery lines do; set EV_LOG_RCPT = $domain to log only the domain.
When something fails
Every failure is unchecked, and the reason says why: pending (the API had not answered within 3 seconds: the check finishes in the background and is cached for the next message), sender_limit, daily_cap, busy, api_limit (the API asked to slow down; the helper waits as long as Retry-After says), no_credits, key_refused, api_error, timeout, network_error, or helper_unavailable (Exim got no answer from the helper). After an answer that later checks would get too, such as a refused key or no credits left, the helper stops calling the API for a while instead of slowing every message down. To switch it all off at once, run systemctl stop ev-helper.socket ev-helper.service. If the helper fails to start 3 times within 60 seconds (a key file it cannot read, a wrong setting), systemd stops starting it and stops the socket, and every check is unchecked (helper_unavailable). Fix the cause (journalctl -u ev-helper says it), then run systemctl reset-failed ev-helper.service ev-helper.socket and systemctl start ev-helper.socket.