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
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.
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.
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?