How to Configure SpamAssassin for Spam Filtering

SpamAssassin analyzes incoming mail content and characteristics to score and filter spam — a mature, widely-used content-based filtering layer that complements SPF/DKIM/DMARC and greylisting.

How SpamAssassin Works

Analyzes each message against many rules (content patterns, header anomalies, sender reputation checks) and assigns a spam score — messages exceeding a configured threshold are flagged or rejected, with the specific handling configurable.

Step 1 — Install SpamAssassin

sudo apt install spamassassin spamc -y

Step 2 — Create a Dedicated User

sudo adduser --system --group spamd

Step 3 — Enable and Configure SpamAssassin

sudo nano /etc/default/spamassassin
ENABLED=1
OPTIONS="--create-prefs --max-children 5 --username spamd --helper-home-dir /home/spamd -s /var/log/spamassassin.log"

Step 4 — Start SpamAssassin

sudo systemctl enable --now spamassassin

Step 5 — Integrate with Postfix

sudo nano /etc/postfix/master.cf
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}

Step 6 — Restart Postfix

sudo systemctl restart postfix

Configuring Spam Score Thresholds

sudo nano /etc/spamassassin/local.cf
required_score 5.0
rewrite_header Subject [SPAM]

Messages scoring above the threshold get their subject line tagged — letting users' mail clients filter tagged messages into a spam folder based on this marker.

Setting Up Automatic Spam Folder Filing (Sieve, with Dovecot)

require "fileinto";
if header :contains "X-Spam-Flag" "YES" {
    fileinto "Junk";
}

A Sieve rule (processed by Dovecot) that automatically files SpamAssassin-flagged mail into a Junk folder, rather than relying solely on subject line tagging.

Training SpamAssassin with Bayesian Filtering

sa-learn --spam /path/to/spam/messages
sa-learn --ham /path/to/legitimate/messages

Training SpamAssassin on your actual mail improves accuracy over time — feed it known spam and known legitimate (ham) examples specific to your mail patterns.

Updating SpamAssassin's Rule Sets

sudo sa-update

Rule sets are regularly updated as spam techniques evolve — schedule this periodically (via cron) to keep filtering effectiveness current.

Balancing False Positives and False Negatives

Too aggressive a threshold causes legitimate mail to be flagged (false positives, genuinely costly if important mail is missed); too lenient lets spam through — tune the threshold based on observed accuracy for your specific mail patterns, and monitor for user complaints about missed legitimate mail.

Common Errors

All mail suddenly flagged as spam — check for a recent rule update causing overly aggressive scoring, or verify your own server's IP/domain hasn't developed a reputation issue affecting its own scoring somehow.

Continue Reading

Browse more articles in Email Hosting & Deliverability.

  • spamassassin configuration, postfix spam filtering, spamassassin postfix integration, email spam score
  • 0 utilizatori au considerat informația utilă
Răspunsul a fost util?

Articole similare

How to Set Up a VPS for Email Marketing (Complete Guide)

Running your own email marketing infrastructure on a VPS gives you full control over...

How to Configure SPF, DKIM, and DMARC (Complete Guide)

SPF, DKIM, and DMARC are the three DNS-based email authentication standards that Gmail, Outlook,...

How to Set Up Reverse DNS (PTR/rDNS) for Email Deliverability

Reverse DNS (PTR record) maps your server's IP address back to a hostname — the opposite of...

IP Warm-Up: A Safe 30-Day Schedule for New Sending IPs

Mailbox providers like Gmail and Outlook monitor sending behavior closely and treat sudden...

Best Email Marketing Software for a VPS (MailWizz, Mautic, Listmonk & More)

Choosing the right self-hosted email marketing platform affects deliverability, ease of...