Training SpamAssassin.

Keep Calm and Train SpamAssassin

 

Everyone receives a different and personal variety of spam which is unique to their particular inbox. That means that SpamAssassin can’t catch everything 100% of the time on its own.

In the event that you receive large amounts of spam, sometimes the usual rules that SpamAssassin applies during the process of scoring the email doesn’t always work as well as you would like it to. You can train SpamAssassin to become better at recognizing spam that is unique to your particular situation.

All that you need to do to train SpamAssassin is to create two new folders for training. Since the IMAP protocol assumes synchronization of local and server folders, you need to ensure that you are using IMAP and not the POP3 mail protocol. The first folder we will call ‘learn-spam’ and the second folder we will call ‘learn-ham’. You may use whatever names that make the most sense to you. Once these folders have been created, you should manually move any spam that have arrived in your inbox into the learn-spam folder. Any good emails (false-positives) that were placed in the Spam or Junk folders should be moved into the learn-ham folder.

If you would like to get premium spam filtering services, you should know that GlowHost now has the option of adding SpamExperts to your hosting solution. Having SpamExperts means that your email will be sanitized and over 99% of recognized incoming spam will be quarantined. There is even the benefit of added security! SpamExperts anti-virus protection helps prevent viruses from entering your systems as well. You can find more information and order it here.

Now for the training part. Please note that this process will work only if you use the IMAP protocol which keeps emails on the server side and synchronizes your mail client with server constantly. POP3 won’t allow you to do this due to the way the protocol works. In order to train SpamAssassin, you will need to add the following cron jobs in cPanel. Just make sure to set the correct values for [username], [domain] and [email] – and don’t include the [ and ] tags.

0 0 * * * /usr/local/cpanel/3rdparty/bin/sa-learn -p /home/[username]/.spamassassin/user_prefs –spam /home/[username]/mail/[domain]/[email]/.learn-spam/{cur,new}

0 0 * * * /usr/local/cpanel/3rdparty/bin/sa-learn -p /home/[username]/.spamassassin/user_prefs –ham /home/[username]/mail/[domain]/[email]/.learn-ham/{cur,new}

For example, if your email address is awesome@glowhost.com and your cPanel username is glowuser, the cron will look like this:

0 0 * * * /usr/local/cpanel/3rdparty/bin/sa-learn -p /home/glowuser/.spamassassin/user_prefs –spam /home/glowuser/mail/glowhost.com/awesome/.learn-spam/{cur,new}

That’s all! SpamAssassin will analyze your spam and ham folders every day, and after some time, you should see fewer false positives in your spam folder and more spam being correctly tagged as junk.

If you would like to have an additional layer of protection from spam, you can configure your mail client. For example, if your mail client is Thunderbird, you go to Tools -> Account Settings and choose “Junk Settings” from the list.

thunderbird configuration

You will be able to set the following settings:

Enable adaptive junk mail controls for this account. 

This option is similar to the server side training method as described above. Depending on what emails you flag as junk by pressing the J button on the keyboard or clicking the icon displayed below, Thunderbird will “study” these junk emails and will use new and different patterns to define spam messages.

junk_message

Trust junk mail headers set by: SpamAssassin

This setting gives the possibility for Thunderbird to automatically read headers set by SpamAssassin and mark spam messages with the junk icon. This is really convenient and a “must have” if you use SpamAssassin.

Move new junk messages to:

Here you can set any folder you would like junk messages to be moved to. Please note that I strongly recommend reviewing junk folders at least once a week to ensure that there are no false positives arriving in those folders. If you find a legitimate message marked by Thunderbird as junk, you can simply remove the icon (or by pressing J on the keyboard) and Thunderbird will remember that. This will help you to avoid new false positives in future.

That’s all there is to it! I hope that this post helps you win the battle against spam!