Netzary

Postfix + Virtual users(Mysql) + maildrop

The best Ubuntu + Postfix + Courier IMAP + MySQL + Amavisd-new + SpamAssassin + ClamAV howto I have seen is Flurdy's Postfix doc. One major thing missing in that is user wise mail filter. There is a link to a posting in that on howto integrate maildrop with this setup. But the problem I encountered in that is maildrop filter considers "virtual" as the user and it is not possible to have a user based filter set up in that. How ever a global filter option sure works with that doc.


These are the steps I followed to make maildrop recognise users from my mysql database and setup per user based filters. The version of courier-maildrop which comes in Ubuntu I think does not come with mysql setup. I followed this link but it did not work for me. If Somebody gets it working do let me know since it saves a lot of time compiling maildrop from scratch. 


 


Download the latest maildrop from http://www.courier-mta.org/download.php#maildrop.


The version I had downloaded is 2.5.0


root@mailserver:~/products/maildrop-2.5.0# ./configure --prefix=/usr/local/courier --enable-maildropmysql --with-mysqlconfig=/usr/local/courier/etc/maildropmysql.config --enable-maildrop-uid=1004 --enable-maildrop-gid=1004


root@mailserver:~/products/maildrop-2.5.0#make


root@mailserver:~/products/maildrop-2.5.0# make install


Now you have successfully installed a courier maildrop version with mysql support. Next is to have the configurations properly put in to so that maildrop can read from it


root@mailserver:~/products/maildrop-2.5.0#cd /usr/local/courier/


root@mailserver:/usr/local/courier#mkdir etc


root@mailserver:/usr/local/courier# vim etc/maildropmysql.config


Make sure the file is updated with the configuration that looks like below.


 


hostname                 localhost
port                          3306
database                 db_name
dbuser                     db_user
dbpw                       db_password
dbtable                    users
default_uidnumber   5000
default_gidnumber   5000
uid_field                   id
uidnumber_field       uid
gidnumber_field       gid
maildir_field             home
homedirectory_field maildir
quota_field             quota
# unused for now, but needs to be a valid field.
mailstatus_field     enabled
#where_clause         AND postfix = 'y'


maildrop for some reason has to be have root as the owner and setuid bit set for it to work with the Flurdy setup.. So do the steps blow to make sure that is done


root@mailserver:/usr/local/courier# chown -R root.root bin/


root@mailserver:/usr/local/courier# chmod +s bin/maildrop


Now we need to have the global maildroprc written. This is where I specified to take the user based filters set by the admin. Also maildrop will have to make the new maildir style directories for new users.


#
# Import variables
#

DEFAULT="$DEFAULT"
SENDMAIL="/usr/sbin/sendmail"
HOME="$DEFAULT"
TEST="/usr/bin/test"
MM="/usr/local/courier/bin/maildirmake"

#
#Create home directory if it does not exist
#
`$TEST -d $DEFAULT && exit 0 || exit 1`
if ( $RETURNCODE != 0 )
{
`$MM $HOME`
}


#
# Check for admin user .adminfilter file
#
ADMIN_FILTER="$HOME.adminfilter"
`$TEST -e $ADMIN_FILTER && exit 0 || exit 1`
if ( $RETURNCODE == 0 )
{
include "$ADMIN_FILTER"
}


Onece this is done maildrop part is taken care of. Now we need to setup postfix to start using maildrop as MDA. You can follow this if you have multiple domains in the same server and want to test out maildrop only for one particular domain. Or else you can follow the below mentioned to have postifx use maildrop globally.


in /etc/postfix/main.cf add these 3 lines



virtual_transport = maildrop
maildrop_destination_recipient_limit = 1
maildrop_destination_concurrency_limit = 1


In /etc/postfix/master.cf you might have two line already for maildrop change it to the one mentioned below


maildrop  unix  -       n       n       -       -       pipe
  flags=R user=virtual argv=/usr/local/courier/bin/maildrop -d ${recipient}


Thats it now reload postfix /etc/init.d/postfix reload and you have Flurdy postfix doc with user based filters.


For an example if you have a user manager@abc.com and you want a copy of "all mails going to manager@abc.com from accenture.com " also to go to director@abc.com. This is the mailfilter rule you can write


You should be creating the filter file in /var/spool/mail/virtual/manager/.adminfilter


 


SENDMAIL="/usr/sbin/sendmail"


if ( /^From:.*accenture\.com/:h )
{
  cc "! director@abc.com"
}


 


Two things you have to do after creating the user based filter file is


chown virtual.virtual /var/spool/mail/virtual/manager/.adminfilter
chmod 600 /var/spool/mail/virtual/manager/.adminfilter


That is it, the above worked for me. I am welcome to comments on how this can be improved.




Added on July 1, 2010 Comment

Comments

Post a comment

Office Location

Contact Information

#3 A, 3rd Floor, Krishna Residency, Langford Road cross, Bangalore - 560025

T: +91-80 41738665
F: +91-80 22112749
E: info@netzary.com