Integrations · Mail servers and panels
Check outgoing recipients in Postfix
A policy service for Postfix 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: its answer to Postfix is always "carry on", so it never refuses a recipient unless you turn that on. When a check cannot be made in time, the API answers with an error or the service is not running, Postfix carries on and the mail goes out as usual. It never asks Postfix to delay mail.
It has two parts: ev-policy, a small daemon (Python 3 standard library, no packages) that Postfix asks through its policy protocol (check_policy_service) over a Unix socket, and one line for your main.cf. Download them as one zip: ev-policy-1.0.0.zip, which unpacks into a folder ev-policy/. Postfix 3.0 or later.
What gets checked
Only outbound mail: the client logged in (SMTP AUTH), or connects from one of your own servers that you list in outbound_networks. Recipients at your own domains are not checked: the ones Postfix delivers or relays for, read from postconf when the service starts, and any you list in local_domains (add the domains Postfix keeps in a lookup table, such as virtual mailbox domains in a database: the service names those parameters when it starts). Mail from other servers to your users is never checked, 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-policy/api-keywithout showing it: as root in bash, runinstall -d -m 0755 /etc/ev-policyand(umask 077; read -rs -p 'API key: ' key && printf '%s\n' "$key" > /etc/ev-policy/api-key; echo), then paste the key at the prompt (it is not shown and stays out of your shell history). Then copyev_policy.pyto/usr/local/lib/ev-policy/andev-policy.confto/etc/ev-policy/, setoutbound_networksto your relay hosts' networks, then runpython3 -I /usr/local/lib/ev-policy/ev_policy.py --check-config.Install
ev-policy.socketandev-policy.servicein/etc/systemd/system/and runsystemctl enable --now ev-policy.socket. The socket is created in Postfix's queue directory, so a chrooted smtpd reaches it, and only Postfix can connect to it. The key stays readable by root only: systemd hands the service its own copy. That needs systemd 247 or later; on an older systemd (RHEL and AlmaLinux 8 have 239), create a system userev-policythat owns the key file, and inev-policy.servicereplaceLoadCredential=andDynamicUser=withUser=ev-policy.Add the line as the first entry of
smtpd_recipient_restrictionsin/etc/postfix/main.cf, above what is there:smtpd_recipient_restrictions = check_policy_service { unix:private/ev-policy, timeout=5s, default_action=DUNNO, try_limit=1 } ...the entries you already have...First, so that no
permitabove it ends the list for the mail it is meant to see; it never answers "accept", so it cannot open a relay there. The settings in braces apply to this check only and keep mail moving when the service cannot answer. If a service inmaster.cf(oftensubmission) has its own list, give it the check through a named list inmain.cf(a plain-oline would break at the spaces):# /etc/postfix/main.cf ev_submission_recipient_restrictions = check_policy_service { unix:private/ev-policy, timeout=5s, default_action=DUNNO, try_limit=1 } permit_sasl_authenticated reject # /etc/postfix/master.cf, in that service's entry -o smtpd_recipient_restrictions=$ev_submission_recipient_restrictionspostfix/main.cf.ev-policyin the zip explains each setting in the braces.Run
postfix check, thenpostfix reload, and try a test address without sending a message:swaks --auth … --quit-after RCPTagainst port 587 ends the session afterRCPT TO, so the check runs and nothing is sent.
Try it on a test server before a production one.
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. Never send a whole message to one: log mode lets every message go out (reject mode too, for a status it does not refuse), and the bounce would hurt your server's sender reputation.
Modes
| Mode | Set | What happens |
|---|---|---|
| Log (default) | nothing | a log line per checked recipient (check rcpt=… status=invalid reason=no_mailbox source=api reply=dunno) |
| Reject | mode = reject | as log, and a recipient whose status is in reject_statuses (default invalid and disposable) is refused with a 5xx text you can edit |
| Header | add_header = yes | as the mode says, and an X-EV-Recipient-Status header for each status among the message's checked recipients |
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 the statuses you list, never a recipient that could not be checked (nor an unknown result that only says our side could not finish the check: reason timeout or internal_error), 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.
The header costs nothing, but a header belongs to the whole message: every copy carries it, local deliveries and Bcc recipients included, so it tells each recipient the statuses of the others, even ones they cannot see. Use it only on a relay with no local mailboxes, for a filter that reads it.
What it costs
Each check the service 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 service 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 login, 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-policy/ev-policy.conf.
Privacy
The service 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: recipients and senders appear as short hashes, with Postfix's queue id.
When something fails
Every failure is answered "carry on", and the log line's 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), slow_api, sender_limit, daily_cap, busy, api_limit (the API asked to slow down; the service waits as long as Retry-After says), no_credits, key_refused, api_error, timeout or network_error. When the service itself is stopped or does not answer within 5 seconds, Postfix carries on by itself (default_action=DUNNO). After an answer that later checks would get too, such as a refused key or no credits left, the service stops calling the API for a while instead of slowing every message down. To switch it all off at once, run systemctl stop ev-policy.socket ev-policy.service. If the service 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 Postfix carries on without checks. Fix the cause (journalctl -u ev-policy says it), then run systemctl reset-failed ev-policy.service ev-policy.socket and systemctl start ev-policy.socket.