How to train SpamAssassin to improve spam detection accuracy on DirectAdmin

Spam, one of the most irritating things when using mail.

In this article I will explain how to configure SpamAssassin to filter spam and to learn from messages you mark as Spam.
Based on assumption messages remaining in your INBOX will be learned as Ham (not spam).

When a message in your INBOX is Spam, you only have to move it to the Spam folder to let SpamAssassin learn it as spam.

 

SpamAssassin Setup

First of all, lets configure SpamAssassin correctly to start filtering Spam.

Go to the Spamassassin Setup page and configure the settings like shown in the below screenshot.

 

spamassassin-settings

Where do you want the spam to go?

Send the spam to the user’s spam folder.

 

What score threshold do you wish to use?

Low Threshold (5.0)

 

Would you like to delete high scoring spam?

Yes, block all spam scoring higher than: 10 (1-50, no decimals)

 

Do you wish to rewrite the subject of a spam email?

No, leave the subject unchanged.

 

How should the spam be delivered?

Don’t use attachments (dangerous).

 

Second is to install a script which will learn what is Spam or Ham to SpamAssassin.

This can be done on two ways, one script that runs as root and starts sa-learn for every mailbox under the user which owns the mailbox or a script that runs as an unprivileged user.

As extra feature it will remove spam messages from INBOX.spam who are older than one month.

 

Learn as unprivileged user

This will explain how to run the script as an unprivileged user, you have to place this script in ~/scripts/sa-learn.sh and create a cronjob to call it once in a while. The interval I choose is 5 minutes. I don’t have many mailboxes so this is fine for me.

 

Don’t forget to make the script executable:

Then add a cronjob to your account via the DirectAdmin control panel.

Optionally instead of mailing the output you can mute the output.

Or mute all output including errors

 

Learn as root user

This will explain how to run the script as root, you have to place this script in /root/scripts/sa-learn.sh and create a cronjob to call it once in a while. The interval I choose is 15 minutes. This is higher than the unprivileged-user script due you have to look through more mailboxes.

 

Don’t forget to make the script executable:

Then add a cronjob to your account via the DirectAdmin control panel.

Optionally instead of mailing the output you can mute the output.

Or mute all output including errors

 

Information

The following links were inspiring or helped me to get the right information how to use SpamAssassin Bayesian classifier.