International Education News
Information media on education around the world
en ja zh
Eliminating spam e-mails

How to eliminate spam mail using SpamAssassin in Postfix

By Author
image
This section explains how to determine and mark spam at the mail server Postfix level.

This article explains how to install SpamAssassin on Postfix on CentOS 7 Linux platform.

Prerequisites

The following conditions have been verified in writing this article.

The Postfix version can be checked with the following method

postconf -d | grep mail_version.

Checking SpamAssassin version

spamassassassin -V.

SpamAssassin installation instructions

$ sudo yum update    
$ sudo yum install spamassassin    

To configure SpamAssassin.

`$ sudo vi /etc/mail/spamassassin/local.cf

In the configuration file, include the following

required_hits 5.0    
report_safe 0    
required_score 5    
rewrite_header Subject [SPAM].    

Create a new user to run SpamAssassin.
Specifically, add the spamd group and create a user without a shell.

$ sudo groupadd spamd    
$ sudo useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd    
$ sudo chown spamd:spamd /var/log/spamassassin    

Enable autostart and start the service

$ sudo systemctl enable spamassassin    
$ sudo systemctl start spamassassin    

Update spam rules.

`$ sudo sa-update

Configuration steps to use SpamAssassin with Postfix

Edit the master.cf file.

$ sudo vi /etc/postfix/master.cf

smtp inet n - n - - - smtpd

Change the line above to the one below

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

Add the following line to the last line.

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

Restart Postfix

$ sudo systemctl restart postfix.

Test spam detection

Test by sending the following mail from outside this mail server.

Title: Anything

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

If configured correctly, you will receive an email in your Inbox with a title beginning with [SPAM].

In addition, check the log.

$ journalctl | grep spam.

Automate spam definition updates

Open crontab.

$ sudo vi /etc/crontab

Set up automatic updates (run daily at midnight)

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

How to check cron execution

grep "sa-update" /var/log/cron

That's all.

TechnologyPostfix

Recommended articles