Want less spam? Learn how to integrate Spamassassin with Postfix Mail Server

The task of preventing the never-ending flow of spam gets a bit simpler with Spamassassin and Postfix.

How to integrate Spamassassin with Postfix Mail Server The task of preventing the never-ending flow of spam gets a bit simpler with Spamassassin and Postfix.

The Postfix Mail Server (a free, open-source mail transfer agent that routes and delivers email) includes a rudimentary content checker. However, given how prevalent SPAM has become, for many businesses that built-in check won't be enough. Because of this, you'll probably want to beef up Postfix with a third-party tool. One such tool is Apache's Spamassassin.

Spamassassin uses a variety of spam-detection techniques, such as DNS- and fuzzy-checksum-based spam detection, Bayesian filtering, external programs, blacklists, and online databases. That's considerably more powerful than the bare-bones check in Postfix. If you find your company getting an inordinate amount of spam through Postfix, that server might need a bit of a boost, with the help of Spamassassin.

SEE: Windows 10 security: A guide for business leaders (Tech Pro Research)

So how do you integrate the two? Let's find out.

Assumptions

I am going to assume that you already have a working Postfix SMTP server running on Linux. I'll demonstrate the installation and integration on the Ubuntu Server 18.04 platform. If your server platform of choice is different, you'll need to modify the installation instructions accordingly.

Installation

Out of the box, Spamassassin isn't installed. To remedy that, open a terminal window and issue the command:

sudo apt-get install spamassassin spamc -y

Once the installation completes, the spamassassin daemon must be started and enabled (so it runs at boot). To do this, issue the following two commands:

sudo systemctl start spamassassin
sudo systemctl enable spamassassin

That's it for the installation. Time to integrate.

Configuring Postfix

Postfix must be configured such that it will pass incoming email through Spamassassin. To do this, open the Postfix configuration file with the command:

sudo nano /etc/postfix/master.cf

Near the very top of that file (Figure A), you'll find a line starting with smtp.

postfixa.jpg

Figure A: The Postfix configuration file.

At the end of that line, add the following:

-o content_filter=spamassassin

So the entire line should look like:

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

Scroll to the bottom of the master.cf file and add the following lines:

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

Save and close that file.

Restart Postfix with the command:

sudo systemctl restart postfix

Postfix and Spamassassin are now working in conjunction, to help prevent spam.

Less spammy email

Congratulations, you should now enjoy less spammy email via Postfix. Your company, and your clients will thank you. This is certainly not the end of the line for the prevention of malicious incoming or outgoing mails on your server, but it's a great (and quick) start. 

Also see

linuxnetworkhero.jpg

Jack Wallen

By Jack Wallen

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.