Page 1 of 1

Sieve support enabled!

Posted: Fri Oct 31, 2014 3:30 pm
by GuzziGuy
I found a couple of queries here about sieve, but none answered. After playing around (quite) a bit with it, I think I have it resolved. This is in Ubuntu 14.04 so things may be slightly different on other OS. I'm showing just the lines that need changing in the configs.

Step 1 - install packages

Code: Select all

apt-get install dovecot-sieve dovecot-manageseived dovecot-lmtpd
I was missing the last one, which had me scratching my head for a bit.

Step 2 - initial dovecot settings

Most of the default configs (extra confs are added when installing packages) will be correct, just a couple to change:

Code: Select all

/etc/dovecot/dovecot.conf

#protocols = imap pop3
protocols = imap pop3 lmtp sieve

Code: Select all

/etc/dovecot/conf.d/20-lmtp.conf

#mail_plugins = $mail_plugins
mail_plugins = sieve
Step 3 - sieve scripts directory

By default, dovecot stores scripts in the user's home directory. But this doesn't work on Vesta because we are using virtual mail users; one CP user account (ie system user) holds all the mail accounts for their domains. We need a different setup; change your paths as required, but I put them in my admin user home directory:

Code: Select all

mkdir /home/admin/sieve
chown admin:mail /home/admin/sieve
chmod 770 /home/admin/sieve
Permissions are important! Then, we configure dovecot to save all scripts in here, in domain/user structure:

Code: Select all

/etc/dovecot/conf.d/90-sieve.conf

#sieve = ~/.dovecot.sieve
sieve = /home/admin/sieve/%d/%n/dovecot.sieve
#sieve_dir = ~/sieve
sieve_dir = /home/admin/sieve/%d/%n/scripts
Step 4 - exim

As others have discovered, this doesn't work yet, because dovecot doesn't know when mail is delivered, and therefore to sieve it. We change exim to deliver mail to dovecot.

Code: Select all

/etc/exim4/exim4.conf.template
look for 'ROUTERS CONFIGURATION section', then 'localuser:'

#transport = local_delivery
transport = dovecot_lmtp 

Code: Select all

/etc/exim4/exim4.conf.template
look for 'TRANSPORTS CONFIGURATION section', then add a new transport

dovecot_lmtp:
    driver = lmtp
    socket = /var/run/dovecot/lmtp
    #maximum number of deliveries per batch, default 1
    batch_max = 200
Step 5 - restart

Code: Select all

service dovecot restart
service exim4 restart
That should do it. You should then be able to use the sieve plugin in RC - or I've installed Horde, which also has a sieve plugin. Both seem to work as expected.

I'm no expert so feel free to take issue with any of the above! I'm particularly unsure about the exim4 config setup - is it save to change exim4.conf.template? Or does it get rebuilt with some changes of Vesta?

If anything changes I'll try to change the top post here so it serves as a guide.

Re: Sieve support enabled!

Posted: Mon Nov 10, 2014 4:45 am
by Steven
This is excellent and I followed this guide to successfully implement sieve support. However..

I noticed some errors in the logs like this;

dovecot_lmtp defer (-46): LMTP error after end of data

And I also noticed that there may be an issue with localdomain emails not getting through (try sending from one domain to another on the same box, and reply + reply) - the 2nd reply back doesn't make it home. Could be just me, but would be good for others to try this out as my mail config is pretty much on par with stock standard vestacp.

Regards Steven

Re: Sieve support enabled!

Posted: Tue Nov 11, 2014 10:46 am
by GuzziGuy
Glad this was helpful!
Steven wrote:dovecot_lmtp defer (-46): LMTP error after end of data
Hmm - I'm not seeing this in either my /var/log/mail.log or /var/log/exim4 - where did you see it? Is it actually causing any problems?
Steven wrote:And I also noticed that there may be an issue with localdomain emails not getting through (try sending from one domain to another on the same box, and reply + reply) - the 2nd reply back doesn't make it home.
You may be having the same issue I did, whereby exim4 requires auth to relay mail between local domains. See viewtopic.php?f=12&t=6183 - does that apply?

Re: Sieve support enabled!

Posted: Fri Jan 09, 2015 6:56 pm
by mxroute
This was excellent work. If I may make one suggestion, you can make this work for more than just the admin user by changing the settings in 90-sieve.conf to this:

Code: Select all

sieve = ~/sieve/%d/%n/dovecot.sieve
sieve_dir = ~/sieve/%d/%n/scripts
That way it picks the home directory of the user running the dovecot process, which is the unix user that owns the domain authenticated on.

Re: Sieve support enabled!

Posted: Fri Feb 16, 2018 4:31 am
by tkramer
Works perfectly on debian 9!

I followed the tip of @mxroute, but all worked ok on the main example!

Thanks!