Install SpamAssassin with Postfix on Ubuntu 20.04

In this article, we’ll explain how to install SpamAssassin with Postfix on Ubuntu 20.04.

Apache SpamAssassin is the Open Source anti-spam platform giving system administrators a filter to classify email and block spam (unsolicited bulk email). It uses a robust scoring framework and plug-ins to integrate a wide range of advanced heuristic and statistical analysis tests on email headers and body text including text analysis, Bayesian filtering, DNS blocklists, and collaborative filtering databases.

Prerequisites

  • A Ubuntu installed server with Postfix
  • A root user access or normal user with administrative privileges.

Install SpamAssassin with Postfix on Ubuntu

1. Keep the server up to date

# apt update -y && apt upgrade -y

2. Install SpamAssassin

Install SpamAssassin using following command.

# apt-get install spamassassin spamc -y

Add one user to assign to SpamAssassin and disable the login.

# adduser spamd –disabled-login

3. Configure SpamAssassin

Now let’s assign newly created user spamd to SpamAssassin and set the log and default home directories.

First, open SpamAssassin configuration file in editor.

# vim /etc/default/spamassassin

Find ENABLED=1 and uncomment it and set it to 0.

# ENABLED=0

Second, find OPTIONS= and add home directory and log file.

# OPTIONS=”–create-prefs –max-children 5 –username spamd –helper-home-dir /home/spamd/ -s /home/spamd/spamd.log”

Finally, find CRON=0 and set to 1.

# CRON=1

Now save and exit the file.

Take a back of SpamAssassin local configuration file and create a new SpamAssassin local configuration file using following command:

# mv /etc/spamassassin/local.cf /etc/spamassassin/local.cf.bk

# vim /etc/spamassassin/local.cf

Copy and paste following lines in the file:

rewrite_header Subject ***** SPAM _SCORE_ *****
report_safe             0
required_score          5.0
use_bayes               1
use_bayes_rules         1
bayes_auto_learn        1
skip_rbl_checks         0
use_razor2              0
use_dcc                 0
use_pyzor               0
ifplugin Mail::SpamAssassin::Plugin::Shortcircuit
endif

Save and exit the file.

4. Configure Postfix

1. Edit your Postfix configuration file.

# /etc/postfix/master.cf

2. Find following entries:

smtp      inet  n       -       y       -       -       smtpd
#smtp      inet  n       -       y       -       1       postscreen
#smtpd     pass  -       -       y       -       -       smtpd
#dnsblog   unix  -       -       y       -       0       dnsblog
#tlsproxy  unix  -       -       y       -       0       tlsproxy
submission inet n       -       y       -       -       smtpd

3. Below the smtp configuration, add a SpamAssassin content filter.

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}

Save and exit the file.

4. Restart Postfix and enable SpamAssassin to run at system startup.

# systemctl restart postfix.service
# systemctl enable spamassassin.service
# systemctl start spamassassin.service

That’s it. The installation and configuration process has been completed successfully.

In this article, we have explained how to install SpamAssassin with Postfix on Ubuntu 20.04.

Ubuntu Server Admin

Recent Posts

How to avoid package End of Life through backporting

In July 2025, git received CVE-2025-48384, a high vulnerability allowing arbitrary code execution when cloning…

3 days ago

Showcasing open design in action: Loughborough University design students explore open source projects

Last year, we collaborated with two design student teams from Loughborough University in the UK.…

1 week ago

Canonical Ubuntu and Ubuntu Pro now available on AWS European Sovereign Cloud

January 15, 2026 – Canonical, the publisher of Ubuntu and provider of open source security,…

1 week ago

How to install GitLab on Ubuntu 24.04

How to install GitLab on Ubuntu 24.04 will be explained in this blog post with…

1 week ago

How to Set Up OpenVPN Access Server on Ubuntu 24.04 (VM) & Connect Using OpenVPN Connect

Do you know what was always there but has increased multiple times in the last…

2 weeks ago

How to build DORA-ready infrastructure with verifiable provenance and reliable support

The Digital Operational Resilience Act (DORA) came into force across the EU on January 17,…

2 weeks ago