Please note that this information is no longer up to date. The content of this site has moved to a new domain DIYMacServer.com which is kept up to date. Apologies for the inconvienince.
I have chosen to train DSPAM by moving the spam messages that I receive into a Junk folder in my mail client. I’ve made a small script that checks all Junk folders on the server and feeds them to DSPAM as false negatives to learn DSPAM what spam looks like. This is currently the easiest way to train DSPAM without having to rely on the web based GUI. Please note that this only works if you use IMAP folders, if your users use POP3 we have to look at another solution.
The script looks into the database of postfixadmin to see which users are defined on your system and where their mail directory is located. It then feeds every single message to DSPAM indicating it as an error and to correct DSPAM’s behaviour. After the message is processed the it is removed from the folder.
You can select which IMAP folder your want to use for storing all your SPAM including false negatives (uncaught spam) by changing this entry in the script (don’t forget the leading .):
SPAM_VIRTUAL_FOLDER=.Junk
You can define the folder where it should get the false positives (email wrongly identified as spam) in this variable (don’t forget the leading .):
NOSPAM_VIRTUAL_FOLDER=.NoSpam
Configure your postfixadmin database settings with these entries in the script:
DBUSER=postfix DBPASS=yourpassword DB=postfix
If you want the script not to delete the identified SPAM when the email has been processed then change the DELETESPAM option in something else than YES, like NO:
DELETESPAM=YES
The same rule is valid for the NotSpam folder. To not delete the email from the folder for false positives set this variable to NO.
DELETENOSPAM=YES
If you copy the script into /etc/periodic/daily and make it executable it will run once a day and learn each users spam.
You can download the script train.dspam here
Please note that DSPAM won’t catch spam at first, you’ll need to train it first. The longer you train it the better it will get. You can use your email client junk mail controls to train DSPAM. Configure your mail client to move emails it identifies into the Junk folder. See the screenshots below on how to configure Mail.app and Thunderbird to do this.
November 16th, 2006 at 4:46 pm
hi. since i updated to your new script version i get:
Thu Nov 16 15:44:45 CET 2006 Begin AutoSpam processing
./dspam.train: line 20: mysql: command not found
Thu Nov 16 15:44:45 CET 2006 End AutoSpam processing
did you change anything else? unfortunately i didn’t backup my old version.
greetings,
Dave
November 16th, 2006 at 6:57 pm
i just added
MYSQLDIR=/usr/local/mysql/bin
on top
and changed the mysql call to
$MYSQLDIR/mysql and so on. maybe that helps others, too.
November 16th, 2006 at 7:03 pm
hmm.. maybe i found a little mistake in the script.
when it runs it sais:
rm: dspam.users: No such file or directory
Thu Nov 16 18:00:23 CET 2006 End AutoSpam processing
it tries to delete a non existant file. maybe there is something wrong?
November 16th, 2006 at 8:11 pm
Thanks Dave, I’ve solved the issue with the dspam.users file and corrected the mysql command. I added MYSQL=/usr/local/mysql/bin/mysql to include the full command line in line with the DSPAM variable.
November 16th, 2006 at 9:32 pm
hmm. but i am still getting this error:
./dspam.train
Thu Nov 16 20:29:23 CET 2006 Begin AutoSpam processing
Thu Nov 16 20:29:23 CET 2006 Processing xxx@yyy.com in /usr/local/virtual/yyy.com/xxx/
rm: dspam.users: No such file or directory
Thu Nov 16 20:29:23 CET 2006 End AutoSpam processing
seems like the dspam.users which should be deleted is not existant.
November 16th, 2006 at 10:27 pm
Sorry, typo… Please try again
November 16th, 2006 at 10:57 pm
excellent. now it works fine!
i am just working on another project (nothing to do with this setup – i work as a freelance music editor), when my client pays (i hope he will) i’ll donate some bucks and i really hope that others donate you some bucks, too for all the time you are donating into these tutorials!
December 28th, 2006 at 6:14 pm
[...] Spam is getting worse, so I’m trying out DSPAM. I’ve added it into my vexim set-up, but during the initial training phase, at least, it’s tedious to have to forward mail to training addresses. I use IMAP, so I figured, it’d be nice to get DSPAM to pull files out of a folder I can just drag unclassified spam into. I found a bash script which does the right thing for postfix. [...]
May 1st, 2007 at 1:14 pm
Is possible use Dspam from command line for analizing a file with emails inside?
May 3rd, 2007 at 1:11 pm
dude,
your idea of training dspam with imap subfolders of spam or ham is a pretty good way to do it, too bad you aren’t using an imap folder but a maildir.. which is not what most of the imap server provide. also this script only works with mysql as dspams backend :/
well, too bad. thank’s for the idea though
June 22nd, 2007 at 10:24 pm
Hello, I’m from Brazil.
Do you have this script for DSPAM+qmail+Mysql ?
June 23rd, 2007 at 1:57 pm
Sorry, I don’t know qmail, maybe someone else can help you.
August 16th, 2007 at 3:35 am
would love to know how to use this with Cyrus IMAP server…. any info would be great.
August 16th, 2007 at 7:30 am
I don’t know, I haven’t got a Cyrus installation so I don’t know what kind of format is used to store email. If Cyrus uses the maildir format it would work just like with Courier !
November 15th, 2007 at 5:47 pm
Hello,
I have dspam working now, and I’m using RoundCube. Dspam marks messages as [SPAM] but it doesn’t put them in the Junk folder. Is there a way to make that happen?
November 15th, 2007 at 8:38 pm
Hi again,
Never mind — I hadn’t read about maildrop yet, but I guess that’s the answer to my question!
P.S. Thanks for this site, it’s a fantastic resource!
April 13th, 2008 at 8:58 am
where i have to put “SPAM_VIRTUAL_FOLDER=.Junk” ?
thanks
April 13th, 2008 at 9:18 am
In the script itself.