Learning Spam With SpamAssassin And All Of Your ISPConfig Clients [ISPConfig 3]

Want to support HowtoForge? Become a subscriber!
Submitted by bswinnerton (Contact Author) (Forums) on Thu, 2010-03-25 12:22. :: Anti-Spam/Virus | Debian | ISPConfig | Ubuntu

Learning Spam With SpamAssassin And All Of Your ISPConfig Clients [ISPConfig 3]

This is a quick way of learning spam from all of your ISPConfig clients by running a quick and simple command. Please note that this is for ISPConfig 3, not 2.

You can start out by creating a new file in /bin. For example sa_learn.

nano /bin/sa_learn

Now once you are in that file you can paste the following:

/usr/bin/sa-learn --spam /var/vmail/*/*/.Junk/*/*
/usr/bin/sa-learn --ham /var/vmail/*/*/cur/*

The first part to this code is the directory of the SpamAssassin learning script, when putting in the --spam it learns it as spam, and --ham learns it has "good" messages. The second part to this code is the directory to your clients' spam folders. So once this is all done, you can learn all spam in your customers' spam folders.

After you have saved that file by clicking ctrl x, you will want to make it executable by doing the following command:

chmod o+x /bin/sa_learn

And then now from the command prompt you can simply type


and it will learn spam and ham!

Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anonymous (not registered) on Sun, 2012-12-23 21:52.

For the learned bayes tokens to actually be used while amavis calls spamassassin, the following line has to go in /etc/spamassassin/local.cf:

bayes_path /var/lib/amavis/.spamassassin/bayes

By default, the learned tokens go to ~/.spamassassin/ of the user under which sa-learn is run where it will never be read (since virtual mailboxes are used). Instead, all tokens have to go under the home directory of the amavis user which is /var/lib/amavis.

To verify that the correct directory is used by spamassassin, execute:

spamassassin -D -t < /usr/share/doc/spamassassin/examples/sample-spam.txt 2>&1 | egrep '(bayes:|whitelist:|AWL)'

You should see these lines:
dbg: bayes: tie-ing to DB file R/O /var/lib/amavis/.spamassassin/bayes_toks
dbg: bayes: tie-ing to DB file R/O /var/lib/amavis/.spamassassin/bayes_seen

Submitted by archbird (registered user) on Tue, 2012-02-14 10:59.
Is it bad to run this script if a lot of the emails in the spam folder is already marked as spam by spamassasin (***SPAM*** in the title) ? Or doesn't it matter?
Submitted by vincenzo Ingrosso (not registered) on Wed, 2010-07-21 16:56.


you have missing in /bin/sa_learn the Maildir so script change to:

/usr/bin/sa-learn --spam /var/vmail/*/*/*/.Junk/*/*
/usr/bin/sa-learn --ham /var/vmail/*/*/*/cur/*

Thank you for your work!

Submitted by planet_fox (registered user) on Sat, 2010-03-27 12:52.

Thank for this short guide, I have translated in Germany. Here you can see


. Best ThanksPlaNet Fox

Submitted by admins (not registered) on Mon, 2010-03-29 11:59.

Its only for small mailservers.
If you've a large mailserver sa-learn say its a too long command, bye..



Submitted by kainhofer (registered user) on Tue, 2013-03-19 01:28.
Simply remove the final * from all commands. If you use maildir, it is sufficient to give the directory name and sa_learn will investigate all mails in the directory.
Submitted by atjensen11 (registered user) on Fri, 2010-03-26 04:04.
What happens after running the sa-learn command from the command line?  Does SpamAssassin continue monitoring the folders into the future?  Rather, does the command have to be kicked off periodically to continue learning?  If the answer is the later, this would likely be included in a cron job correct?
Submitted by Adan0s (not registered) on Sat, 2010-03-27 12:30.
you need to put it into a cronjob to let it automatically process the spam/ham
Submitted by skoena (registered user) on Fri, 2010-04-30 07:44.
How should we setup this cronjob?