To enable our mailserver to drop emails in pre-defined mail folders we needed an extra program, we needed another delivery agent. Untill now we have been using ‘virtual‘ one of the standard programs that come with Postfix. I’ve chosen to use maildrop as I have good experience with the other courier programs. If you like you can also another popular agent called ‘procmail‘, but I don’t use that.

You can download the maildrop software from it’s website. Unpack the archive and we can start compiling:

./configure --enable-maildirquota \
--enable-maildrop-uid=102 \
sudo make install

When all went without a problem we can start configuring Postfix to use this new program. First we need to create a new transport to send our emails to maildrop. There is already an entry for maildrop in /etc/postfix/ but you need to replace that one with this one:
maildrop unix – n n – - pipe
  flags=DRhu user=_vmail argv=/usr/local/bin/maildrop /etc/maildroprc -d ${user}@${nexthop} ${extension} ${recipient} ${user} ${nexthop} ${sender}

If you are still using Tiger use this line:
maildrop unix – n n – - pipe
  flags=DRhu user=vmail argv=/usr/local/bin/maildrop /etc/maildroprc -d ${user}@${nexthop} ${extension} ${recipient} ${user} ${nexthop} ${sender}

Please note that the last lines starting with ‘flags’ are actually one line and should be added like one line to If you don’t use maildrop already you can change this without affecting the current workings of your mailserver as the maildrop transport isn’t used yet.

Next we change the config file in /etc/postfix/ to start using the new transport:

Please change:

virtual_transport = virtual


virtual_transport = maildrop

and add this line at the bottom to prevent multiple emails to be send at once to maildrop which might cause unwanted errors:

maildrop_destination_recipient_limit = 1

Next up maildrop filtering, we need to create a filter for maildrop in ‘/etc‘ to tell it what to do with the incoming mails. I’ve made a simple filter to move all spam detected by DSPAM to be put automatically in the Junk folder. This is how my maildroprc looks like:

if (/^X-DSPAM-Result: Spam*/)
  to “$MAILHOME/$HOST/$USER/.Junk/”

If you are using a different location for your virtual mails please change the MAILHOME variable accordingly. To enable maildrop to use and read the file we need to change the ownership and set it to be read and write only to that user the way maildrop likes to see it.

sudo chown vmail maildroprc
sudo chmod 600 maildroprc

You can read more about how to write your filters on the maildrop website in the documentation section.

Now, if you are comfortable with the changes you made we can restart the affected programs to activate the changes.

sudo /usr/local/sbin/authdaemond stop
sudo /usr/local/sbin/authdaemond start
sudo postfix reload