Integrations · Mail servers and panels
Check outgoing recipients in rspamd
A plugin for rspamd that checks the recipients of the mail your users send out and adds a symbol for each result. By default every symbol scores 0, so it only logs: you see in rspamd's history and log which messages go to addresses that cannot receive mail, and nothing changes for the mail. Refusing is something you turn on. When a check cannot be made in time, the API answers with an error or the helper is not running, the recipient is unchecked and the message goes on as usual.
rspamd scans a whole message after DATA, so this is not a refusal at RCPT TO: when you turn refusing on, the whole message is refused at the end of DATA, for every recipient. To refuse one recipient while the others still get the message, use the Exim or Postfix guide instead.
It has two parts: the plugin, a short Lua file for rspamd, and ev-helper, the small daemon of the Exim guide (Python 3 standard library, no packages), which holds the API key, the cache and the limits. The plugin asks the helper over TCP on the same machine, at 127.0.0.1 or ::1 only, and never calls the API or any other host itself. Download the plugin, its settings and the helper's two extra lines as one zip: ev-rspamd-1.0.0.zip, which unpacks into a folder ev-rspamd/.
What gets checked
Only mail from a client that logged in (SMTP AUTH, what rspamd knows as the message's user), which is the mail your users send out. Each SMTP recipient is asked about once per message, up to 20 (max_recipients); the rest go on unchecked. Mail from other servers to your users is not checked: with only_authenticated = false every message rspamd scans is, inbound mail too, and each recipient costs a check.
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.
Install ev-helper as steps 2 and 3 of the Exim guide say (the key goes in at a hidden prompt; the helper and its systemd units come in the Exim zip); you need no Exim changes. Then add the two lines of
ev-helper-tcp.conffrom this zip to/etc/ev-helper/ev-helper.conf:tcp_listen = 127.0.0.1 tcp_port = 11339The helper accepts only 127.0.0.1 or ::1 there (and a port from 1024), so no other machine can ask it. Any account on this machine can, though, unlike the helper's Unix socket, which only Exim's group reaches: it can spend checks (bounded by the helper's daily limit and the key's daily credit cap, not by the limit per sender, since it names the sender itself), learn from a cached answer that someone on the server mailed an address recently, take up the helper's connections, and, while the helper is not listening, open the port itself and answer the plugin falsely. Turn the TCP listener on only on a server where you trust every local account, never on shared hosting (there, use the Exim, cPanel/WHM or DirectAdmin setup, whose Unix socket only Exim can reach). Run
python3 -I /usr/local/lib/ev-helper/ev_helper.py --check-config.On a server without Exim, copy
systemd/ev-helper.socket.d/no-exim.confto/etc/systemd/system/ev-helper.socket.d/(the helper's socket unit names Exim's group otherwise). Then runsystemctl daemon-reload,systemctl enable --now ev-helper.socket ev-helper.serviceandsystemctl restart ev-helper.service(a helper that already runs reads the new lines only when it restarts): rspamd asks over TCP, which does not start the helper by itself, so the service runs from boot.Copy
plugins.d/email_validation.luato/etc/rspamd/plugins.d/and appendemail_validation.confto/etc/rspamd/rspamd.conf.local(rspamd turns a plugin of its own on only when its section is there). Runrspamadm configtest, thensystemctl reload rspamd.Try a test address without sending anything: save any message as a file and run
rspamc --user alice --rcpt no_mailbox@sandbox.email-validation.org < message.eml. rspamc only scans it, and the result listsEV_RCPT_INVALIDwith a short hash and the reasonno_mailbox.
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. Never send a whole message to one: with the default scores it goes out, and the bounce would hurt your server's sender reputation.
Symbols, scores and refusing
Each checked recipient adds one of six symbols, in the group email_validation: EV_RCPT_VALID, EV_RCPT_INVALID, EV_RCPT_CATCH_ALL, EV_RCPT_UNKNOWN, EV_RCPT_DISPOSABLE, or EV_RCPT_UNCHECKED when the helper did not check it. Each option is a short hash of the recipient and its reason (3f2a9c1d0b4e:no_mailbox), never the address.
| You want | Set in the section | What happens |
|---|---|---|
| Log only (default) | nothing | the symbols and their options show in rspamd's history and log; every score is 0 |
| A score | scores { invalid = 5.0; } | the symbol adds that score for each recipient with that status (three invalid recipients add 15), and your actions (add header, reject) work as for any other symbol |
| Refuse | reject = true; | a message with a recipient whose status is in reject_statuses (default invalid) is refused at the end of DATA with reject_message |
Refusing is off by default, because it refuses the whole message, for every recipient, and no check is perfect. It never refuses for unknown or unchecked, even if you list them. Your user sees the refusal in their mail program at once, instead of a bounce later.
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 the plugin passes), its daily limit for all senders together and the key's daily credit cap bound what the plugin spends, as in the Exim guide. Another program on the server that asks the helper over TCP names its own sender, so only the daily limit and the key's cap bound it.
Privacy
The helper sends each 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 its settings, see EU data residency), never in a URL and to no other host. The plugin passes the address to the helper over TCP on this machine only, where any local account can also ask the helper (see step 2). Neither logs the API key or an address: the plugin's symbol options and log lines hold short hashes (set your own hash_salt so they are yours alone), the helper's cache keyed hashes.
When something fails
Every failure is EV_RCPT_UNCHECKED, never a refusal, and its option's reason says why: helper_unavailable (the helper did not answer within the plugin's timeout, 4 seconds, or is not running), bad_answer, bad_address, too_many (past max_recipients), or the helper's own reasons (pending, sender_limit, daily_cap, busy, api_limit, no_credits, key_refused, api_error; see the Exim guide). The recipients are asked at the same time, so a message waits at most about that long. To switch it all off, set enabled = false; in the section (or remove it) and reload rspamd.
Versions
Written for rspamd 4.3 and ev-helper on Python 3.12 or later with systemd 247 or later. The helper's TCP listener is tested with the rest of its test suite; the plugin itself has not yet run under rspamd, so try it on a test server first.