Integrations · Mail servers and panels
Check outgoing recipients in Sendmail
A mail filter (milter) for Sendmail that checks the recipients of the mail your users send out, at RCPT TO. By default it only logs each result and accepts every recipient, so it never refuses one unless you turn that on. When a check cannot be made in time, the API answers with an error or the filter is not running, Sendmail carries on and the mail goes out as usual.
It has three parts: ev-milter, the filter Sendmail talks to over a Unix socket (Python 3 standard library: no libmilter or pymilter to install); ev-helper, the same small daemon as in the Exim guide, which holds the API key, the cache and the limits and makes the checks; and one INPUT_MAIL_FILTER line for your sendmail.mc. Download them as one zip: ev-sendmail-1.0.0.zip, which unpacks into a folder ev-sendmail/. Sendmail 8.14 or later with milter support (8.18 targeted), systemd 247 or later.
This filter was built from Sendmail's milter protocol and tested against stand-ins; it has not yet run on a real Sendmail server, so try it on a test server first.
What gets checked
Only outbound mail: the client logged in (SMTP AUTH, Sendmail's {auth_authen}), or connects from an address in relay_hosts (by default this machine, so messages submitted with the sendmail command, which reach the server through Sendmail's submission program on 127.0.0.1, are checked too). Recipients Sendmail delivers itself (its local mailers) and any domain you list in skip_domains are not checked. Mail from other servers to your users is never checked.
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, from the unpackedev-sendmail/folder, runinstall -D -m 0644 helper/ev_helper.py /usr/local/lib/ev-helper/ev_helper.pyandinstall -m 0644 helper/ev-helper.conf /etc/ev-helper/, then runpython3 -I /usr/local/lib/ev-helper/ev_helper.py --check-config.Copy
systemd/ev-milter.sysusersto/etc/sysusers.d/ev-milter.confand runsystemd-sysusers(it creates the groupev-helper-clients). Installsystemd/ev-helper.socketandsystemd/ev-helper.servicein/etc/systemd/system/, andsystemd/ev-helper-sendmail.confwithinstall -D -m 0644 systemd/ev-helper-sendmail.conf /etc/systemd/system/ev-helper.socket.d/sendmail.conf(it gives the helper's socket to that group instead of Exim's). Runsystemctl daemon-reloadandsystemctl enable --now ev-helper.socket.Run
install -D -m 0644 milter/ev_milter.py /usr/local/lib/ev-milter/ev_milter.pyandinstall -D -m 0644 milter/ev-milter.conf /etc/ev-milter/ev-milter.conf(the service runs as its own user, so the settings file must stay readable), add your relay hosts torelay_hostsif you have any, and runpython3 -I /usr/local/lib/ev-milter/ev_milter.py --check-config. Installsystemd/ev-milter.socketandsystemd/ev-milter.servicein/etc/systemd/system/and runsystemctl enable --now ev-milter.socket.Try it without sending mail:
python3 -I /usr/local/lib/ev-milter/ev_milter.py --test no_mailboxasks the helper about the free test addressno_mailbox@sandbox.email-validation.organd prints its status and what the filter would do.Add the line in
sendmail/ev-milter.mcto yoursendmail.mc, below any otherINPUT_MAIL_FILTERlines:INPUT_MAIL_FILTER(`ev-milter', `S=local:/run/ev-milter/ev-milter.sock, T=C:5s;S:5s;R:10s;E:30s')Rebuild
sendmail.cf(on Debian and Ubuntusendmailconfig, on AlmaLinux and Rockymake -C /etc/mail) and restart Sendmail. The line has noF=flag on purpose: when the filter is down or does not answer, Sendmail carries on as if it were not there. That also means a Sendmail that cannot reach the socket skips the filter without a word, so check the log line in the next step: with SELinux enforcing (AlmaLinux and Rocky), Sendmail may need a local policy module to connect to/run/ev-milter/ev-milter.sock, and if your Sendmail setsRunAsUser, give that user's group the socket (SocketGroup=andSocketMode=0660inev-milter.socket).Try a recipient in a session that logs in and ends after
RCPT TO, so nothing is sent:swaks --server localhost --port 587 --auth-user <user> --to no_mailbox@sandbox.email-validation.org --quit-after RCPT, then read the log line withjournalctl -u ev-milter. Never send a whole message to a test address: log mode lets it out and the bounce hurts your sender.
Modes
- Log only (
mode = log, the default): every recipient is accepted, and each checked one gets a line in the journal with Sendmail's queue id, a short hash of the address (never the address), its status and reason. - Reject (
mode = reject): a recipient whose status isinvalidwith a reason inreject_reasonsis refused atRCPT TOwith550 5.1.1andreject_text; the message still goes to the other recipients. Defaults:reject_reasons = no_mailbox no_dns no_inbound_mail unroutable, andreject_disposable = no(set it toyesto refuse disposable addresses too). A recipient that could not be checked,unknown,catch_allandvalidare never refused.
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). The helper's cache, its limit per sender (the login, else the client's address), its daily limit for all senders and the key's daily credit cap bound what it spends, as the Exim guide explains; every limit but the last 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 in ev-helper.conf, see EU data residency), never in a URL and to no other host. The filter has no network access and never sees the key. Neither log holds the key or an address: recipients appear as short hashes, with Sendmail's queue id.
When something fails
Every failure accepts the recipient, and the log line's reason says why: helper_timeout (no answer from the helper within helper_timeout = 4 seconds), helper_unavailable (its socket is missing or it hung up), bad_answer, or the helper's own reasons (pending, sender_limit, daily_cap, no_credits, key_refused, api_error and the others the Exim guide lists). When the filter itself is stopped or slow, Sendmail skips it (no F= flag; R:10s stays above the filter's own wait). To switch it all off at once, run systemctl stop ev-milter.socket ev-milter.service, or remove the line from sendmail.mc and rebuild.