Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
View unanswered posts
View posts from last 24 hours

Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message

Joined: 08 Jul 2003
Posts: 239

PostPosted: Thu Feb 17, 2005 6:41 pm    Post subject: DSPAM + QMAIL + VPOPMAIL + PROCMAIL Reply with quote

after finding out what dspam was i was ultra pumped to try it out.
the installation of this program was frustrating to say the least and i hope that this will help someone out there to keep their hair unlike me :)

for the majority of the guide i followed the qmail/vpopmail Virtual Mail Hosting System Guide

i found the guide to be outdated on some path names doing this from a stage3 install yesterday.
there are a couple finer points that need a little attention

check the structure of the hostfile so that the fqdn is resolved properly by hostname
having hostname and fqdn sqitched in position will cause some problems
ip_addr   fqdn    hostname

in your use flags make sure you have set
USE="maildir apache2 mysql imap nls ssl" 

ipv6 was on for my builds but i dont think that its necessary

from this point you can follow the qmail vpopmail guide
when you get to the section detailing courier-imap, some things have changed
you still have to build vpopmail before courier, but specifically courier-authlib not courier-imap

the authdaemonrc file has been moved from


the guide also tells you to make the authdaemonrc containg only authvchkpw but if this is done, you cannot use imap on your real user accounts. if you need to have access via imap to your local user account then include authpam
otherwise you need to re-alias system messages to be sent to your virtual user account if you want to receive them

you will not be able to send mail to your unix users if you setup vpopmail to handle mail for that domain.
before vpopmail would give mail to my unix user
after vpopmail would bounce back as undeliverable
i didnt research to see if there is a way to map them together or not, just something i noticed before setting up a virtual for myself anyway. im sure that you could symlink the maildirs together or soemthing as a hack just to get the messages since you probably wont use the account for real email anyway ;)

once you have setup and started courier-imap, be sure to restart courier-authlib just to make sure your auth setting has taken effect. during my installation i was getting an sql access error because i didnt restart courier-authlib

after this point i installed imp as the guide suggested and personally i like it a bit better than squirrelmail ;)
make sure vpopmail and qmail are working properly, if they are then we can go ahead and try to get some dspam in there...

heres how i got dspam working.
emerge dspam

then. you have to setup dspam and mysql to work together nicely
in /etc/mail/dspam there are a few .sql files the ones we are interested in are
mysql_objects-space.sql mysql_objects-speed.sql mysql_virtual_users.sql
get get these into my sql you need to do the following

create a dspam database in mysql, i used dspam for my db name
then you need to run the sql files
mysql should ask you for a password when you do this. use your mysql root password
cat mysql_objects-space.sql | mysql dbname -p
cat mysql_objects-speed.sql | mysql dbname -p
cat mysql_virtual_users.sql | mysql dbname -p

then you have to set the proper permissions
mysql -u root -p

grant select, insert, update, delete on dbname.* to desireddspamusername identified by 'desireddspampassword'

now we need to update dspam.conf so it knows whats going on
(this section is near the middle of the file, not at the very end. )
MySQLServer    /var/run/mysqld/mysqld.sock
MySQLUser      dspamusername
MySQLPass      dspampasswd
MySQLDb        dsspamdbname
MySQLCompress  true

now for the most frustrating part.
every guide and the dspam readme.qmail file say that you should be able to make a .qmail file and put a line in that pipes email through dspam, at that point i guess its supposed to just pass any mail it doesnt see as spam
this didnt work so enter procmail to the equation.

emerge procmail

were going to create a .qmail file for the virtual users so that qmail doesnt hand off email to vdelivermail.
in /var/vpopmail/domains/domainname/ we need to make a .qmail file for each user you want to filter spam for.
to test this out i made a test user to play with until this was up and running.
.qmail-username should contain
| procmail -t ./test/.maildir/procmailrc

now that procmail is going to take control, we can pipe to dspam from here.. and then use procmail rules for filtering if we like.. i would suggest putting the recipe for non dspam delivery into the file first and sending a test message just to make sure that procmail is picking up the ball on this. i read that the procmailrc paths need to be relative to the domainname root folder for vpopmail. if you move it you will have to change the folder paths you use.
for the test user i put the procmailrc file in /var/vpopmail/domains/domainname/user/.maildir/procmailrc
in procmailrc put
#the first line will deliver spam as well as ham the options used here match what is in the dspam qmail readme
#| dspam --stdout --deliver=spam,innocent --mode=teft --user full@email.addy --feature=chained,noise,whitelist
| dspam --stdout --deliver=innocent --mode=teft --user full@email.addy --feature=chained,noise,whitelist
### Deliver the rest into Maildir normally

the last thing you have to do is setup dspam to get train on false negatives, the easiest way to do this seems to be setting a cron up to run and grab mail out of a spam folder for this purpose.
i made a script in /etc/mail/dspam called containing


if [ $# -ne 2 ]; then
   echo Usage: $0 domainname username
   exit 1

cd $VPOPDIR/domains/$1/$2/.maildir/.spam/cur
for NAME in `ls -1`; do
   cat $NAME | $DSPAMDIR/dspam --user $2@$1 --mode=teft --class=spam --source=error
   rm -f $NAME

set permissions
chmod u+x

add a cron to do this
crontab -u vpopmail -e

in the crontab
#run the scanner once a week on monday at 3am
0 3 * * 1  /etc/dspam/ domainname username

i hope this guide proves useful. any comments/explanations/suggestions are welcome, i dont know a lot about dspam and perhaps a guru could shed some light or a little cleaner script. it would be nice to have a script that would scan all spam folders for all users for all domains so you dont have to keep adding to the cron.
it would also be nice if there was a way to use a procmail file dynamically so you could just reference one file instead of having to create one for every user. if anyone has any ideas/wants to help that would be appreciated.

thanks and happy spam filtering!!!
Back to top
View user's profile Send private message

Joined: 16 Jan 2004
Posts: 273
Location: Göteborg, Sweden

PostPosted: Fri Jul 08, 2005 12:11 pm    Post subject: Re: DSPAM + QMAIL + VPOPMAIL + PROCMAIL Reply with quote

bruor wrote:

in /var/vpopmail/domains/domainname/ we need to make a .qmail file for each user you want to filter spam for.
to test this out i made a test user to play with until this was up and running.
.qmail-username should contain
| procmail -t ./test/.maildir/procmailrc

Thank you for a nice guide.

I have a suggestion for the section that I qouted above.

I just spent two hours troubleshooting my setup.
Mail to went through, but not mail to

I found the answer in the dot-qmail manpage:
In the qmail system, you control all local addresses of the
form user-anything, as well as the address user itself,
where user is your account name. Delivery to user-anything
is controlled by the file homedir/.qmail-anything. (These
rules may be changed by the system administrator; see

The alias user controls all other addresses. Delivery to
local is controlled by the file homedir/.qmail-local, where
homedir is alias's home directory.

In the following description, qmail-local is handling a
message addressed to local@domain, where local is controlled
by .qmail-ext. Here is what it does.

If .qmail-ext is completely empty, qmail-local follows the
defaultdelivery instructions set by your system

If .qmail-ext doesn't exist, qmail-local will try some
default .qmail files. For example, if ext is foo-bar,
qmail-local will try first .qmail-foo-bar, then .qmail-foo-
default, and finally .qmail-default. If none of these
exist, qmail-local will bounce the message. (Exception: for
the basic user address, qmail-local treats a nonexistent
.qmail the same as an empty .qmail.)

WARNING: For security, qmail-local replaces any dots in ext
with colons before checking .qmail-ext. For convenience,
qmail-local converts any uppercase letters in ext to

This means ANY email address username that contains a dot must be translated before you use it as a dot-qmail file.
Thus, => .qmail-test
and => .qmail-jonas:widarsson

Did you see the colon?

One other note, that is not covered in the guide:
If you deliver through the .qmail-default file:
| /usr/bin/dspam  --deliver=innocent --user $EXT@$USER  --stdout | /var/vpopmail/bin/vdelivermail '' bounce-no-mailbox
and use vdelivermail (or anything else I guess), beware that dspam will get called prior to any vpopmail alias processing you may have setup, since any redirection vdelivermail wants to make happens AFTER dspam.

I have the setup where some email addresses are common to a group of our staff. I set up an email account called

Then I can add any alias to that address.

then I connect that address as an alias for any user that I wish to add to the "common group".
like this:
ns1 # valias -s -> -> -> ->
[... split for readability] -> -> ->
ns1 #

so if one sends email to, it first gets redirected to, which redirects to all the guys me, him and her.
If DSPAM is called before vdelivermail like I show above, this means dspam will process the email and add its headers three times before it reaches the destination account. I confirmed this by sending an email to common as well, and got the headers added twice instead of thrice.

This is really space waste, not to mention the tripled server load... :roll:

So don't do that!
Instead, do something like the suggestion in the guide above.

Last edited by jonaswidarsson on Mon Jul 11, 2005 12:00 pm; edited 1 time in total
Back to top
View user's profile Send private message

Joined: 08 Jul 2003
Posts: 239

PostPosted: Fri Jul 08, 2005 11:41 pm    Post subject: Reply with quote

thanks for the update on this howto a bit, it was my first hack at getting qmail working with all this stuff and i wasnt quite sure if everything was working or not.

can you confirm that dspam is working in this configuration? i wasnt able to confirm any results other than the database was logging that the email had passed through it. perhaps a version or 2 has gone by since, but either way its a good thing that its working for you ;)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum