SpamAssassin is the most widely-used open-source spam filter. Integrated with Postfix via Amavis, it scores incoming email and filters spam before it reaches your mailbox.
Step 1 — Install SpamAssassin and Amavis
sudo apt install amavis spamassassin clamav clamav-daemon -y
sudo systemctl enable amavis --now
Step 2 — Configure SpamAssassin
sudo nano /etc/spamassassin/local.cf
required_score 5.0
use_bayes 1
bayes_auto_learn 1
rewrite_header Subject [SPAM]
# Whitelist your domain
whitelist_from *@yourdomain.com
# Blacklist known spam sources
blacklist_from *@spammer.com
Step 3 — Configure Amavis
sudo nano /etc/amavis/conf.d/15-content_filter_mode
use strict;
@bypass_virus_checks_maps = (1); # Keep enabled
@bypass_spam_checks_maps = (0); # Enable spam checking
1;
Step 4 — Connect Postfix to Amavis
sudo nano /etc/postfix/main.cf
content_filter = amavis:[127.0.0.1]:10024
sudo nano /etc/postfix/master.cf
Add at the end:
amavis unix - - - - 2 smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
127.0.0.1:10025 inet n - - - - smtpd
-o content_filter=
-o local_recipient_maps=
-o smtpd_restriction_classes=
Step 5 — Train Bayesian Filter
# Train with known spam
sa-learn --spam /path/to/spam/folder
# Train with legitimate email
sa-learn --ham /path/to/ham/folder
# Check statistics
sa-learn --dump magic
Step 6 — Restart Services
sudo systemctl restart postfix amavis spamassassin
Conclusion
SpamAssassin with Bayes filtering catches 95%+ of spam. Our team configures complete anti-spam mail server setups for production environments.
Comments