Rspamd is a fast, modern spam filter that scores every message using many checks – SPF, DKIM, DMARC, blocklists, Bayesian learning, fuzzy hashes – and can also DKIM-sign outgoing mail. This guide connects Rspamd to a Postfix mail server.
Before you start
- A working Postfix (and ideally Dovecot) mail server with root access.
- At least 1–2 GB of free RAM for Rspamd and Redis.
- A local DNS resolver such as Unbound is recommended, because public resolvers are often blocked by DNS blocklists.
Note: cPanel servers use SpamAssassin (Apache SpamAssassin in cPanel) or Imunify; don't add Rspamd by hand there.
Install Rspamd and Redis
- Add the official Rspamd repository for your distribution (instructions on the Rspamd website), then install:
sudo apt install -y rspamd redis-serverOn AlmaLinux/Rocky use
sudo dnf install -y rspamd redisafter adding the repo. - Start both:
sudo systemctl enable --now redis rspamd(Redis service may beredis-serveron Debian/Ubuntu).
Basic configuration
Put local settings in /etc/rspamd/local.d/ – never edit the main files.
redis.conf:servers = "127.0.0.1";actions.conf(scores are examples – start conservative):reject = 15; add_header = 6; greylist = 4;milter_headers.conf:use = ["x-spamd-bar", "x-spam-level", "authentication-results"];classifier-bayes.conf:autolearn = true;
Connect Postfix
Add to /etc/postfix/main.cf:
smtpd_milters = inet:127.0.0.1:11332
non_smtpd_milters = inet:127.0.0.1:11332
milter_default_action = accept
milter_protocol = 6Reload with sudo systemctl reload postfix. milter_default_action = accept keeps mail flowing if Rspamd is down.
Enable DKIM signing
- Generate a key:
sudo mkdir -p /var/lib/rspamd/dkim sudo rspamadm dkim_keygen -s mail -d example.com -k /var/lib/rspamd/dkim/example.com.mail.key | sudo tee /var/lib/rspamd/dkim/example.com.mail.txt sudo chown -R _rspamd:_rspamd /var/lib/rspamd/dkimThe user is
rspamdon some systems. - In
local.d/dkim_signing.conf:path = "/var/lib/rspamd/dkim/$domain.$selector.key"; selector = "mail"; allow_username_mismatch = true; - Publish the TXT record from the
.txtfile atmail._domainkey.example.com. - Restart Rspamd and send a test to a mailbox that shows headers; look for
dkim=pass.
Web interface
- Set a password:
rspamadm pw, and put the hash inlocal.d/worker-controller.incaspassword = "HASH";. - The UI listens on
127.0.0.1:11334. Reach it through an SSH tunnel or a password-protected reverse proxy – don't expose it publicly.
Move spam to Junk and train the filter
- Use Dovecot's Sieve plugin to file messages with an
X-Spam: Yesheader into Junk. - Use Dovecot's
imapsieveto callrspamc learn_spam/learn_hamwhen users move mail into or out of Junk.
Troubleshooting
- No Rspamd headers on mail: check the milter line in Postfix and
journalctl -u rspamd. - Too much legitimate mail rejected: raise
reject, and check the symbol breakdown in the web UI history. - DNSBL checks always fail: use a local resolver instead of public DNS.
- Test the config:
rspamadm configtest.
FAQ: Rspamd
Rspamd or SpamAssassin?
Rspamd is faster and includes DKIM/ARC signing and a web UI; SpamAssassin is older and well integrated into panels like cPanel and Plesk.
Does Rspamd need Redis?
It works without it, but Bayes learning, greylisting and rate limits depend on Redis.
Can Rspamd scan for viruses?
Yes, by connecting to ClamAV through its antivirus module.
