Spamassain

---------

Configure Spamassassin Centos 8

Operating System :

hostnamectl

Postfix :

postconf -d | grep mail_version

Spamassassin (if already installed) :

spamassassin -V

Install and Configure Spamassassin

dnf update -y

dnf -y install spamassassin*

Let's configure spamassassin, create or edit this file

# vim /etc/mail/spamassassin/local.cf

Uncomment or insert the following:

required_hits 5.0

report_safe 0

required_score 5

rewrite_header Subject [**SPAM**]

Create new group and user to run spamassassin

# groupadd spamd

# useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd

Change owner of spamassassin log file to user spamd

chown spamd:spamd /var/log/spamassassin

Enable spamassassin service to run automaticly when server reboot

systemctl enable spamassassin

Lets start spamassassin service

systemctl start spamassassin

Then update spamassassin database with

sa-update

Configure Postfix to Work with Spamassassin

Open postfix master config

vim /etc/postfix/master.cf

Add filter spamassassin on smtp/smtpd on the top of config file

smtp      inet  n       -       n       -       -       smtpd -o content_filter=spamassassin

And add this line at the end of line of config file

spamassassin unix - n n - - pipe flags=R user=spamd argv=/usr/bin/spamc -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}

Restart postfix service

postmap /etc/postfix/master.cf

systemctl restart postfix

Test Spam Detection

We will test by sending email to this mail server with this content message of body :

XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X

Automate Update Spamassassin Database

We can running spamassassin update database sa-update automaticly with crond service. We will set it to run automatic every night at 01.00 

Open and edit file 

vim /etc/crontab

Add this cronjob

00 01 * * * root /bin/sa-update && /sbin/service spamassassin restart

Restart crond service with

systemctl restart crond

spamassassin -D < /usr/share/doc/spamassassin-3.4.0/sample-spam.txt

 sa-update --nogpg

 ss -tnlp | grep spamd

 spamassassin --lint

 spamassassin --lint -D

 systemctl restart spamassassin

-----------