Install spamassassin with postfix on ubuntu 20. 04

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.

See also  How To Use the C Programming Language in Ubuntu 22.04

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.


Discover more from Ubuntu-Server.com

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply