Are you tired of being spam in your inbox? If the answer is yes you can reduce spam in your inbox by install SpamAsassin on your mail server. Or you can show this post to your networks/web server administrator to install spamassasin at your mail server.
Here we will use SpamAssasin with Postfix to handle email spam filter. Postfix is a widely used mail transport agent (MTA) used on many popular Unix/Linux systems. And SpamAsassin is one of the apache project is to filter the email. Below is the step to install and configure spamassasin, and this step is for Ubuntu/Debian, for other OS please refer to SpamAsassin official site.
How to install SpamAssasin
- Install spamasassin and spamc with this command:
sudo apt-get install spamassassin spamc
- Create specific user for spamAsassin with this command:
groupadd -g 5001 spamd useradd -u 5001 -g spamd -s /sbin/nologin -d /var/lib/spamassassin spamd mkdir /var/lib/spamassassin chown spamd:spamd /var/lib/spamassassin
- Configure setting in spamAsassin, open /etc/default/spamassassin and then make the setting like below:
ENABLED=1 SAHOME="/var/lib/spamassassin/" OPTIONS="--create-prefs --max-children 5 --username spamd --helper-home-dir ${SAHOME} -s ${SAHOME}spamd.log" PIDFILE="${SAHOME}spamd.pid"
- Configure SpamAsassin rules, open /etc/spamassassin/local.cf and then make the setting like below:
rewrite_header Subject [***** SPAM _SCORE_ *****] required_score 2.0 #to be able to use _SCORE_ we need report_safe set to 0 #If this option is set to 0, incoming spam is only modified by adding some "X-Spam-" headers and no changes will be made to the body. report_safe 0 # Enable the Bayes system use_bayes 1 use_bayes_rules 1 # Enable Bayes auto-learning bayes_auto_learn 1 # Enable or disable network checks skip_rbl_checks 0 use_razor2 0 use_dcc 0 use_pyzor 0
- Start SpamAsassin with this command:
sudo/etc/init.d/spamassassin start
- Now we need to tell postfix to use SpamAsassin, edit /etc/postfix/master.cf and change the line:
smtp inet n - - - - smtpd
to
smtp inet n - - - - smtpd -o content_filter=spamassassin
Then add this:
spamassassin unix - n n - - pipe user=spamd argv=/usr/bin/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}
- Reload Postfix with this command:
sudo /etc/init.d/postfix reload
That’s it. Hope this post can help you to reduce spam in your inbox. Have a nice day…
Disclaimer: Use these instructions at your own risk. I am not an expert on spam filtering: this set of instructions just gave me what I needed to do my own local spam filtering. If you set it up and it loses you the email clinching a one million dollar contract, I assume no responsibility.
Hi,
Great post, only thing I've noticed, all emails I now send from my server get SPAM prefixed to the subject. I was hoping it would do that to incoming email, not email I send.
Any ideas? Cheers, Lee.
Hi,
Great post, only thing I’ve noticed, all emails I now send from my server get SPAM prefixed to the subject. I was hoping it would do that to incoming email, not email I send.
Any ideas? Cheers, Lee.
Remove the line
required_score 2.0
from /etc/postfix/master.cf, so it will use the default score, 5.0.
sorry, the right file is…
/etc/spamassassin/local.cf
not /etc/postfix/master.cf
Thanks for the tips tomlobato 🙂