Today I am going to show how to create a simple spam filter running on your linux box using SpamAssassin and Postfix. It basically works on any linux distribution which has these 2 packages installed.

I am going to assume that you already have a fresh install of postfix and spamassasin.

Spamassasin: how to create a simple spam filter using bash and spamc

First we have to create a linux user. The spam filter will run under that user. I am going to use user: spamcheck for now:

Then we create a filter file which invoques spamassassin‘s binary spamc. Name the file spamcheck for example and create it in /bin/spamcheck with the following content:

Now set the right permissions the SpamAssasin shell script and /var/spamcheck folder:

Now go to postfix configuration folder (/etc/postfix) and edit master.cf file. Add somewhere at the beggining of the file the entry bellow:

Spamassassin filter test

Save the file and reload postfix (service postfix reload). Spamassassin daemon (spamd) daemon should be running in order to have a working spam filter for postfix. You can check the status of spamd using:

Send yourself an email and check postfix logs (tail -f /var/log/maillog) to see if the filter is working. If you’re seeing something like in the link bellow, then you succeded:

 





Share.

About Author

I am a linux passionate and currently working as a Linux Senior System Administrator. I also am a freelancer and help people to complete different jobs. You can hire me on Freelancer.com