1. Home
  2. Email
  3. Spam Protection
  4. How to train SpamAssassin

How to train SpamAssassin

Table of Contents

By default, Spamassassin is set to auto learn on all inbound mail. This works fairly well in most cases by itself and you normally don’t have to do anything. In most cases, it will get more accurate over time.

However, in some situations, it may be helpful to train SpamAssassin yourself. This will help prevent good emails from going to spam, and bad emails from getting to your inbox.

To set this up, you need to use the sa-learn program which is only available to customers who have their email addresses configured to utilize the IMAP service.

How to train SpamAssassin

1) Create a folder titled spam within webmail or your email client.

2) Subscribe to the newly created spam folder using the Subscribe/Unsubscribe Folder feature of your webmail or email client.

3) Next, we need to set up a cron jobs to automate the training process. For information on how to configure the commands listed below in a cronjob, please choose your panel from the link below.

We will need to configure both of the commands individually within their own cron jobs to ensure that the learning process will work.

Example #1:

To have training learn from one email address on a specific domain that you have configured:

/usr/local/cpanel/3rdparty/bin/sa-learn -p ~/.spamassassin/user_prefs --spam ~/mail/$domain.tld/$mailbox/.spam/{cur,new} >/dev/null 2>&1
/usr/local/cpanel/3rdparty/bin/sa-learn -p ~/.spamassassin/user_prefs --ham ~/mail/$domain.tld/$mailbox/{cur,new} >/dev/null 2>&1

Example #2:

To have training learn from all the email address of a particular domain that you have configured:

/usr/local/cpanel/3rdparty/bin/sa-learn -p ~/.spamassassin/user_prefs --spam ~/mail/$domain.tld/*/.spam/{cur,new} >/dev/null 2>&1
/usr/local/cpanel/3rdparty/bin/sa-learn -p ~/.spamassassin/user_prefs --ham ~/mail/$domain.tld/*/{cur,new} >/dev/null 2>&1

Example #3:

To have training learn from all the email address on all additional domains that you have configured:

/usr/local/cpanel/3rdparty/bin/sa-learn -p ~/.spamassassin/user_prefs --spam ~/mail/*/*/.spam/{cur,new} >/dev/null 2>&1
/usr/local/cpanel/3rdparty/bin/sa-learn -p ~/.spamassassin/user_prefs --ham ~/mail/*/*/{cur,new} >/dev/null 2>&1

Please Note: This will send all messages that SpamAssassin believes to be good (ham) into your inbox and all the messages that it finds bad (spam) into the spam folder on your account. If a spam message slips through the filter and ends up in your inbox, simply move it to your spam folder instead of deleting it as this will allow the program to learn that this message should be in spam the next time it runs. This is also the case for when a message that is good(ham) ends up in the spam folder, simply move it back to your inbox.

In the event that you wish to change the folder in which your spam and ham messages are filtered to, you will need to repeat the same steps as above where you create the folder, subscribe to it and then schedule the cron job. The only change is that you need to modify the folder name in the path for your cron job.

Please note: The commands are case sensitive, so if you create a folder as Good then you must specify it as .Good in your command (see below)

Example 4:

To have training learn from one email address on one domain using custom folders (junk & good).

/usr/local/cpanel/3rdparty/bin/sa-learn -p ~/.spamassassin/user_prefs --spam ~/mail/$domain.tld/$mailbox/.junk/{cur,new} >/dev/null 2>&1
/usr/local/cpanel/3rdparty/bin/sa-learn -p ~/.spamassassin/user_prefs --ham ~/mail/$domain.tld/$mailbox/.good/{cur,new} >/dev/null 2>&1

That’s it! You now know how to set up training with SpamAssassin. If you have any questions, please feel free to leave a comment below, or you can contact our 24/7 support team via Client Area.

Updated on August 9, 2020

Was this article helpful?

Related Articles

TRY CHEMICLOUD RISK-FREE
Fast, secure cloud hosting. 18 global data centers. Unhappy with your web host?
👉 Migrate for Free

Comments

  1. Hm. But as just wildcard for the folder is used in some examples, would it not include the spam folder in the ham learning, and make the ham leaning less effective? Should not the spam folder be excluded?

Leave a Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.