Getting incoming spam mails to your server can be very annoying, especially if you have already configured many settings to stop the rate of spams.
In this post, let us have a look through the SpamAssassin (SA) training which has been found very useful in cutting the rate of spam mails. SA comes with a feature in which it can learn itself over a given period of time and distinguish b/w spam mails and non-spam mails. As a user, all you need to do is write a script to analyze the mails using this tool ‘
sa-learn‘ and feed it with some examples of spam and ham mails.
The steps which will be followed are :
– Select the email account for which you wish to have this configured for and open it in webmail.
– Create two folders SA-spam and SA-ham in your mailbox
– Now SSH to your server and create a script
sa-learn.sh in the document root of the domain for which you wish to have SA training enabled for.
#!/bin/sh /usr/bin/sa-learn --no-sync --spam /home/username/mail/[domain]/[mailbox]/.SA-spam/cur /usr/bin/sa-learn --no-sync --ham /home/username/mail/[domain]/[mailbox]/.SA-ham/cur /usr/bin/sa-learn --sync rm -f /home/username/mail/[domain]/[mailbox]/.SA-spam/cur rm -f /home/username/mail/[domain]/[mailbox]/.SA-ham/cur
Replace ‘domain’ and ‘mailbox’ with your own values.
chmod 755 /home/username/sa-learn.sh
chown username.username /home/username/sa-learn.sh
– Now lets configure a cron to run this once a day,
crontab -e -u username
and add this entry and save the cron.
0 0 * * */home/username/sa-learn.sh > /dev/null 2>&1
Once this much has been completed, you would need to feed SA with some sample mails. When the spam mails hit your mailbox, move it to SA-spam folder and also copy some of the good mails to SA-ham folder. You must keep in mind that if you move the good mails to SA-ham, after the SA processes the mails, it would delete the good mails as well. So either copy the good mails to SA-ham or make sure you do not need them in future.
Make sure your account is set as IMAP, when doing this from an email client.
Over the time, SA would train itself and it would efficiently differentiate b/w spam and non-spam mails.