Dovecot is a very powerful mail imap and po3 mail server. It also has a Sieve server integrated. We describe here in 3 steps how to install sieve for dovecot on a CentOS 6 linux distribution. This howto assume that dovecot is already running as well a mta server like postfix, exim or sendmail.
1 – Verify that dovecot is the lda
For sieve to work we need to use dovecot as a lda. This means that dovecot has to write the email to the email folder of the user for the final delivery. To verify that dovecot is the lda we can send an email to any user hosted by dovecot and grep the maillog file in real time like this.
tail -f /var/log/maillog | grep lda Feb 8 16:33:07 localhost dovecot: lda(jeandebogue): msgid=<52F64E34.2030408@wedebugyou.com>: saved mail to INBOX Feb 8 16:33:07 localhost postfix/local[2253]: 1B829BF666: to=<jeandebogue@am02.wedebugyou.com>, orig_to=<test@wedebugyou.com>, relay=local, delay=0.13, delays=0.04/0/0/0.09, dsn=2.0.0, status=sent (delivered to command: /usr/libexec/dovecot/deliver)
In the previous command we see that dovecot is the lda and is responsible to write the email to disk.
What to do if dovecot is not the lda?
If you don’t see a similar line it means that probably your mta is responsible for writing the email to the disk.
Dovecot
First of all verify that dovecot has the lda protocol enabled.
Here is the dovecot config responsible for the lda service in dovecot /etc/dovecot/conf.d/15-lda.conf.
protocol lda { # Space separated list of plugins to load (default is global mail_plugins). mail_plugins = sieve postmaster_address = postmaster@wedebugyou.com }
Postfix
Second verify that your mta is configure to send the email to dovecot. You will need to check in the documentation and here is how to enable this with postfix.
Change the value mailbox_command in the postfix config file /etc/postfix/main.cf.
mailbox_command = /usr/libexec/dovecot/deliver
2 – Install sieve
yum install dovecot-pigeonhole
That was easy.
3 – Configure sieve
Make sure that your plugin { } in /etc/dovecot/conf.d/90-plugin.conf look like this:
plugin { # setting_name = value # Sieve sieve=~/.dovecot.sieve sieve_dir = ~/sieve sieve_global_dir = /home/sieve sieve_max_script_size = 1M }
Change the protocols line in /etc/dovecot/dovecot.conf
protocols = imap pop3 sieve
Uncomment these lines in /etc/dovecot/conf.d/20-managesieve.conf
service managesieve-login { inet_listener sieve { port = 4190 }
Finally, add these lines into this file /home/jeandebogue/.dovecot.sieve of the user that needs a sieve rule.
require "fileinto"; if header :contains "subject" "test" { fileinto "test"; }
This sieve rule means if the email subject contains the word test, move the email into the test folder.
Don’t forget to create an imap folder call test!
Restart dovecot
service dovecot restart
Now if you send an email to the same user with a subject test you should see this in your maillog and also the email should be automatically move to the folder test.
Feb 8 17:56:12 wdy02 dovecot: lda(jeandebogue): sieve: msgid=<52F661AD.3020303@wedebugyou.com>: stored mail into mailbox 'test' Feb 8 17:56:12 wdy02 postfix/local[1114]: B4654BF582: to=<jeandebogue@am02.wedebugyou.com>, orig_to=<noc@wedebugyou.com>, relay=local, delay=0.15, delays=0.04/0.01/0/0.1, dsn=2.0.0, status=sent (delivered to command: /usr/libexec/dovecot/deliver)
It doesn’t work, I need help
If you follow these steps and you still can’t figure it out, you can enable more debug in dovecot to try to understand the problem. Change this value in /etc/dovecot/conf.d/10-logging.conf.
mail_debug = yes
It still doesn’t work, can you help me?
The values of dovecot and sieve should not be change on a live system without knowing what do they do. Enabling sieve on a live system is no trivial task. If you need help to enable sieve for dovecot on CentOS, please contact us and we will do it for you.
Jean Debogue
Latest posts by Jean Debogue (see all)
- Phoenix project: Canada first - March 2, 2018
- How to install sieve for dovecot on CentOS 6? - February 8, 2014
- How to Protect Successfully your network against DDoS attacks: 5 steps - November 23, 2013
Thanks a lot!
Your “How-To” worked “out-of-the-box”, except, I had to append “sieve” to line “protocols” in file /etc/dovecot/dovecot.conf:
protocols = pop3 imap sieve
Thanks again!
I updated the post with your comment and I agree it was forgotten.
Thanks again Evald