Filtering spam in Postfix is pretty simple. There’s some advanced techniques you can use, but simply setting up Spamassassin will suit many people. One downside is seeing all the ***** SPAM ***** mails in your inbox. It took a while to come up with a solution, but the best fit so far has been implementing Maildrop to automatically move those files to a Junk folder. Here’s the steps to set this up on a Debian 5.0 system with Postfix and Spamassassin.
First, setup your /etc/maildroprc file:
# commands and variables for making the mail directories
maildirmake=/usr/bin/maildirmake
mkdir=/bin/mkdir
rmdir=/bin/rmdir
MAILDIR=$DEFAULT
# make the user's mail directory if it doesn't exist
`test -e $MAILDIR`
if ($RETURNCODE != 0)
{
`$mkdir -p $MAILDIR`
`$rmdir $MAILDIR`
`$maildirmake $MAILDIR`
}
# make the .Junk folder if it doesn't exist
JUNK_FOLDER=.Junk
_JUNK_DEST=$MAILDIR/$JUNK_FOLDER/
`test -d $_JUNK_DEST`
if ($RETURNCODE != 0 )
{
`$maildirmake $_JUNK_DEST`
#auto subscribe. the following works for courier-imap
`echo INBOX.Junk >> $MAILDIR/courierimapsubscribed`
}
# If the Spam-Flag is set, move the mail to the Junk folder
if (/^X-Spam-Flag:.*YES/)
{
exception {
to $DEFAULT/.Junk/
}
}
The comments clearly state what’s going on there.
Once that’s setup, you will go into your /etc/postfix/master.cf and make sure the
maildrop unix - n n - - pipe
flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
is not commented out.
Next you will have to set the /usr/bin/maildrop file setuid root. This is so maildrop can interact with authdaemon and the mail folders.
#chmod +s /usr/bin/maildrop
The last thing you have to do is add this to your /etc/postfix/main.cf file:
virtual_transport = maildrop maildrop_destination_recipient_limit = 1
If there is another virtual_transport line, be sure to comment that out first.
And that’s all. Nice and simple way to handle all that Junk mail.
#1 by Mario on February 21, 2010 - 11:04 pm
Hello, I have a Postfix with MySQL virtual domains, using this guide: http://bit.ly/gHxde but when I change the last two lines in main.cf (virtual_transport = maildrop
maildrop_destination_recipient_limit = 1) I got this error when sending mail to my users:
I’m sorry to have to inform you that your message could not
be delivered to one or more recipients. It’s attached below.
For further assistance, please send mail to postmaster.
If you do so, please include this problem report. You can
delete your own text from the attached returned message.
The mail system
: user unknown. Command output: ERR: authdaemon:
s_connect() failed: Permission denied Invalid user specified.
Final-Recipient: rfc822; user@domain.tld
Original-Recipient: rfc822;user@domain.tld
Action: failed
Status: 5.1.1
Diagnostic-Code: x-unix; ERR: authdaemon: s_connect() failed: Permission denied
Invalid user specified.
#2 by steve on February 22, 2010 - 12:27 am
In this line right here:
maildrop unix – n n – – pipe
flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
that is placed in your master.cf you notice a user=vmail argument. Change this user= to the user appropriate for your system. This is the user that actually writes to the disk where the mail directory is stored.
I hope this helps.
#3 by Matt on March 13, 2010 - 8:23 pm
Hi,
I have my mail server setup like http://www.howtoforge.com/virtual-users-domains-postfix-courier-mysql-squirrelmail-ubuntu9.04
I’ve setup and got maildrop working on as far as moving the junk to the right place etc.
However it’s creating /home/vmail/Maildir/
and putting it all in there, Do you know why that would be?
#4 by steve on March 13, 2010 - 8:51 pm
The system thinks the home directory is /home/vmail. I wish I could tell you why but I can’t without more information.
#5 by Matt on March 13, 2010 - 8:54 pm
FYI i’m set up as follows
/home/vmail/domain/user
I’d appreciate the help with this, I can’t find anything on the net :(