Docs / Email Servers / Fighting Spam with SpamAssassin

Fighting Spam with SpamAssassin

By Admin · Feb 25, 2026 · Updated Apr 23, 2026 · 32 views · 1 min read

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 spamc

Enable and Start

sudo systemctl enable --now spamassassin

Integrate 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 1

Training 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 magic

Testing

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.34X

This string should trigger a spam score of 1000.

Was this article helpful?