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

Life at Canonical: Victoria Antipova’s perspective as a new joiner in Product Marketing

Canonical is continuously hiring new talent. Being a remote- first company, Canonical’s new joiners receive…

22 hours ago

What is patching automation?

What is patching automation? With increasing numbers of vulnerabilities, there is a growing risk of…

2 days ago

A beginner’s tutorial for your first Machine Learning project using Charmed Kubeflow

Wouldn’t it be wonderful to wake up one day with a desire to explore AI…

3 days ago

Ubuntu brings comprehensive support to Azure Cobalt 100 VMs

Ubuntu and Ubuntu Pro supports Microsoft’s Azure Cobalt 100 Virtual Machines (VMs), powered by their…

3 days ago

Ubuntu Weekly Newsletter Issue 870

Welcome to the Ubuntu Weekly Newsletter, Issue 870 for the week of December 8 –…

4 days ago

Get Valkey security patching and support with Ubuntu Pro

Canonical is pleased to announce security patching and support for Valkey through the Ubuntu Pro…

4 days ago