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:
--enable-maildrop-uid=102 \
--enable-maildrop-gid=102
make
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/master.cf but you need to replace that one with this one:
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:
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 master.cf. 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 main.cf config file in /etc/postfix/ to start using the new transport:
Please change:
into:
and add this line at the bottom to prevent multiple emails to be send at once to maildrop which might cause unwanted errors:
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:
EXTENSION=”$1″
USER=”$5″
HOST=”$6″
MAILHOME=”/usr/local/virtual”
DEFAULT=”$MAILHOME/$HOST/$USER/.”
if (/^X-DSPAM-Result: Spam*/)
{
to “$MAILHOME/$HOST/$USER/.Junk/”
}
else
{
to “$MAILHOME/$HOST/$USER/”
}
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 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 start
sudo postfix reload



1:26 am
Why not use sieve filtering? Why use an MTA to dot this?
3:31 am
Maildrop is an MDA (Mail Delivery Agent) not an MTA (Mail Transport Agent) and sieve seems to be a filtering language, which would be implemented by… you guessed it… an MDA.
One would use an MDA like Maildrop, because it understands virtual users and virtual hosts, as implemented by the Courier MTA and its utilities (of which Maildrop is a member)
Sieve does look nice, but it’s not an entire solution, it’s a language, supported / implemented by MTA’s or MDA’s.