Introduction
SpamAssassin is an open-source spam filtering platform that uses a variety of techniques including header analysis, Bayesian filtering, DNS blocklists, and custom rules to identify unwanted email.
Installation
sudo apt update
sudo apt install -y spamassassin spamcEnable and Start
sudo systemctl enable --now spamassassinIntegrate with Postfix
Edit /etc/postfix/master.cf. Change the smtp line and add a spamfilter:
smtp inet n - y - - smtpd
-o content_filter=spamassassin
spamassassin unix - n n - - pipe
user=spamd argv=/usr/bin/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}Configuration
Edit /etc/spamassassin/local.cf:
required_score 5.0
rewrite_header Subject [SPAM]
report_safe 0
use_bayes 1
bayes_auto_learn 1Training the Bayesian Filter
# Train with known spam
sa-learn --spam /path/to/spam-folder/
# Train with known good mail
sa-learn --ham /path/to/good-mail/
# Check database stats
sa-learn --dump magicTesting
Send the GTUBE test string in an email body to verify SpamAssassin is working:
XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34XThis string should trigger a spam score of 1000.