Setting up server side mail filtering

This is a follow up to my former article “Setting up a spamsafe Postfix server“. I will describe how to extend that installation to use Sieve for server side mail filtering in Dovecot. This article is based on an Ubuntu 10.04 installation but should work with other Linux distributions.

Filtering is done in the final mail delivery stage. Normally Postfix will write the messages directly into the Maildir of the user. We need to change the Postfix setting to use the Dovecot delivery agent. Edit the file /etc/postfix/ and add the following line:

mailbox_command = /usr/lib/dovecot/deliver

After a restart, Postfix will forward received messages to Dovecot for delivery:

sudo /etc/init.d/postfix reload

The deliver tool uses the configuration file /etc/dovecot/dovecot.conf. Make sure that this file is globally readable:

sudo chmod 644 /etc/dovecot/dovecot.conf

Now we need to edit the file /etc/dovecot/dovecot.conf and enable sieve and managesieve functionality. First enable the managesieve protocol. Search the line with the protocols entry and add managesieve as a new protocol:

protocols = imap imaps pop3 pop3s managesieve

Now make sure that the section lda is enabled and contains the following settings:

protocol lda {
  postmaster_address =
  mail_plugins = sieve

Set the path to your sieve scripts in the plugin section:


You can now restart Dovecot:

sudo /etc/init.d/dovecot restart

Server side mail filterin should now be working. You can test it by setting up some rules. I would recommend to use a webmail client like Roundcube to do this. Roundcube has a very nice client plugin for the managesieve protocol.

Leave a Reply