Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Main Section Mail Server
  • Search

Tutorial: Sieve, Managesieve filters with Dovecot and Roundcube.

Questions regarding the Mail Server
Dovecot, Exim, RoundCube
Post Reply
  • Print view
Advanced search
10 posts • Page 1 of 1
zdi
Posts: 6
Joined: Fri May 06, 2016 5:34 pm

Tutorial: Sieve, Managesieve filters with Dovecot and Roundcube.
  • Quote

Post by zdi » Fri May 06, 2016 5:40 pm

I want to thank Jeffery Tay for his help.

Without further ado:


#Install Dovecot Manage Sieve

yum install dovecot-pigeonhole

#edit 20-managesieve.conf
nano /etc/dovecot/conf.d/20-managesieve.conf

#Uncomment protocols
protocols = $protocols sieve

#Edit 10-master.conf
#add in section listed in blue

nano /etc/dovecot/conf.d/10-master.conf

service auth {
unix_listener auth-client {
group = mail
mode = 0660
user = dovecot
}
unix_listener auth-master {
group = mail
mode = 0660
user = dovecot
}

user = dovecot
}

#Append this to the end of 10-master.conf
service managesieve-login {
inet_listener sieve {
port = 4190
}
}
service managesieve {
}
protocol sieve {
managesieve_max_line_length = 65536
managesieve_implementation_string = dovecot
log_path = /var/log/dovecot-sieve-errors.log
info_log_path = /var/log/dovecot-sieve.log
}
plugin {
sieve = ~/.dovecot.sieve
sieve_global_path = /etc/dovecot/sieve/default.sieve
sieve_dir = ~/sieve
sieve_global_dir = /etc/dovecot/sieve/global/
}
lda_mailbox_autocreate = yes
lda_mailbox_autosubscribe = yes
protocol lda {
mail_plugins = $mail_plugins autocreate sieve quota
postmaster_address = [email protected]
hostname = srv.testdomain.com
auth_socket_path = /var/run/dovecot/auth-master
log_path = /var/log/dovecot-lda-errors.log
info_log_path = /var/log/dovecot-lda.log
}
protocol lmtp {
mail_plugins = $mail_plugins autocreate sieve quota
log_path = /var/log/dovecot-lmtp-errors.log
info_log_path = /var/log/dovecot-lmtp.log
}

#touch and set the permissions on the log files, else you will get permission errors
touch /var/log/dovecot-lda-errors.log
chmod 660 /var/log/dovecot-lda-errors.log
chown dovecot.mail /var/log/dovecot-lda-errors.log

touch /var/log/dovecot-lda.log
chmod 660 /var/log/dovecot-lda.log
chown dovecot.mail /var/log/dovecot-lda.log

touch /var/log/dovecot-lmtp-errors.log
chmod 660 /var/log/dovecot-lmtp-errors.log
chown dovecot.mail /var/log/dovecot-lmtp-errors.log

touch /var/log/dovecot-lmtp.log
chmod 660 /var/log/dovecot-lmtp.log
chown dovecot.mail /var/log/dovecot-lmtp.log

#Create default sieve rule

mkdir /etc/dovecot/sieve
nano /etc/dovecot/sieve/default.sieve
require ["fileinto"];
# rule:[SPAM]
if header :contains "X-Spam-Flag" "YES" {
fileinto "Spam";
}

touch /etc/dovecot/sieve/default.sieve
chmod +w /etc/dovecot/sieve/default.sieve
chown dovecot.mail /etc/dovecot/sieve/default.sieve

#Restart dovecot, if service starts, means configuration is successful
service dovecot restart

#Configure roundcube

nano /etc/roundcubemail/config.inc.php
$rcmail_config[‘plugins’] = array(‘managesieve’);

nano /usr/share/roundcubemail/plugins/managesieve/config.inc.php.dist

// default contents of filters script (eg. default spam filter)
$config[‘managesieve_default’] = ‘/etc/dovecot/sieve/default.sieve’;

#Configure Exim, modify part in purple
nano /etc/exim/exim.conf
localuser:
driver = accept
#transport = local_delivery
transport = dovecot

condition = ${lookup{$local_part}lsearch{/etc/exim/domains/$domain/passwd}{true}{false}}



######################################################################
# TRANSPORTS CONFIGURATION #
######################################################################
begin transports

dovecot:
driver = pipe
command = /usr/libexec/dovecot/dovecot-lda -e -d $local_part@$domain -f $sender_address -a $original_local_part@$original_domain
return_path_add
log_output = true
delivery_date_add
envelope_to_add
user = ${extract{2}{:}{${lookup{$local_part}lsearch{/etc/exim/domains/$domain/passwd}}}}
group = mail
return_output


#Restart exim, if service starts, means configuration is successful
service exim restart
Top

gogoi
Posts: 10
Joined: Tue Dec 01, 2015 3:20 am

Re: Tutorial: Sieve, Managesieve filters with Dovecot and Roundcube.
  • Quote

Post by gogoi » Thu Dec 22, 2016 7:21 am

Hello!

This solution works fine with real linux accounts.

This send a single autoresponser message for all virtual email accounts in a domain under a linux vestacp account

BUT how can this work with virtual email accounts under a linux account?
Top

plvsouza
Posts: 1
Joined: Wed Sep 27, 2017 2:36 am

Re: Tutorial: Sieve, Managesieve filters with Dovecot and Roundcube.
  • Quote

Post by plvsouza » Wed Sep 27, 2017 2:42 am


Updated tutorial to work with centos7 and virtual mail accounts

#Install Dovecot Manage Sieve

Code: Select all

yum install dovecot-pigeonhole
#edit 20-managesieve.conf

Code: Select all

nano /etc/dovecot/conf.d/20-managesieve.conf
#Uncomment protocols

Code: Select all

protocols = $protocols sieve
#Edit 10-master.conf

Code: Select all

nano /etc/dovecot/conf.d/10-master.conf
#add auth-master unix-listener to service auth

Code: Select all

service auth {
  unix_listener auth-client {
    group = mail
    mode = 0660
    user = dovecot
  }
  unix_listener auth-master {
    group = mail
    mode = 0660
    user = dovecot
  }
  user = dovecot
}
#Append this to the end of 10-master.conf

Code: Select all

service managesieve-login {
  inet_listener sieve {
    port = 4190
  }
}

service managesieve {
}

protocol sieve {
  managesieve_max_line_length = 65536
  managesieve_implementation_string = dovecot
  log_path = /var/log/dovecot-sieve-errors.log
  info_log_path = /var/log/dovecot-sieve.log
}

plugin {
  sieve = ~/mail/%d/%n/dovecot.sieve
  sieve_global_path = /etc/dovecot/sieve/default.sieve
  sieve_dir = ~/mail/%d/%n/sieve
  sieve_global_dir = /etc/dovecot/sieve/global/
}

lda_mailbox_autocreate = yes

lda_mailbox_autosubscribe = yes

protocol lda {
  mail_plugins = $mail_plugins autocreate sieve quota
  postmaster_address = [email protected]
  hostname = srv.testdomain.com
  auth_socket_path = /var/run/dovecot/auth-master
  log_path = /var/log/dovecot-lda-errors.log
  info_log_path = /var/log/dovecot-lda.log
}

protocol lmtp {
  mail_plugins = $mail_plugins autocreate sieve quota
  log_path = /var/log/dovecot-lmtp-errors.log
  info_log_path = /var/log/dovecot-lmtp.log
}
#edit 90-sieve.conf

Code: Select all

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

Code: Select all

plugin {
  # The path to the user's main active script. If ManageSieve is used, this the
  # location of the symbolic link controlled by ManageSieve.
  #sieve = ~/.dovecot.sieve
  sieve = ~/mail/%d/%n/dovecot.sieve

  # The default Sieve script when the user has none. This is a path to a global
  # sieve script file, which gets executed ONLY if user's private Sieve script
  # doesn't exist. Be sure to pre-compile this script manually using the sievec
  # command line tool.
  # --> See sieve_before fore executing scripts before the user's personal
  #     script.
  #sieve_default = /var/lib/dovecot/sieve/default.sieve

  # Directory for :personal include scripts for the include extension. This
  # is also where the ManageSieve service stores the user's scripts.
  #sieve_dir = ~/sieve
  sieve_dir = ~/mail/%d/%n/sieve
#touch and set the permissions on the log files, else you will get permission errors

Code: Select all

touch /var/log/dovecot-lda-errors.log
chmod 660 /var/log/dovecot-lda-errors.log
chown dovecot.mail /var/log/dovecot-lda-errors.log

Code: Select all

touch /var/log/dovecot-lda.log
chmod 660 /var/log/dovecot-lda.log
chown dovecot.mail /var/log/dovecot-lda.log

Code: Select all

touch /var/log/dovecot-lmtp-errors.log
chmod 660 /var/log/dovecot-lmtp-errors.log
chown dovecot.mail /var/log/dovecot-lmtp-errors.log

Code: Select all

touch /var/log/dovecot-lmtp.log
chmod 660 /var/log/dovecot-lmtp.log
chown dovecot.mail /var/log/dovecot-lmtp.log
#Create default sieve rule

Code: Select all

mkdir /etc/dovecot/sieve
nano /etc/dovecot/sieve/default.sieve

Code: Select all

require ["fileinto"];
# rule:[SPAM]
if header :contains "X-Spam-Flag" "YES" {
  fileinto "Spam";
}

Code: Select all

touch /etc/dovecot/sieve/default.sieve
chmod +w /etc/dovecot/sieve/default.sieve
chown dovecot.mail /etc/dovecot/sieve/default.sieve
#Restart dovecot, if service starts, means configuration is successful

Code: Select all

service dovecot restart
#Configure roundcube

Code: Select all

nano /etc/roundcubemail/config.inc.php

Code: Select all

$config['plugins'] = array(
    'archive',
    'zipdownload',
    'password', 
    'managesieve',
);

// default contents of filters script (eg. default spam filter)
$config['managesieve_default'] = '/etc/dovecot/sieve/default.sieve';
#Configure Exim

Code: Select all

nano /etc/exim/exim.conf

Code: Select all

localuser:
  driver = accept
  #transport = local_delivery
  transport = dovecot
  condition = ${lookup{$local_part}lsearch{/etc/exim/domains/$domain/passwd}{true}{false}}



######################################################################
# TRANSPORTS CONFIGURATION #
######################################################################
begin transports

dovecot:
  driver = pipe
  command = /usr/libexec/dovecot/dovecot-lda -e -d $local_part@$domain -f $sender_address -a $original_local_part@$original_domain
  return_path_add
  log_output = true
  delivery_date_add
  envelope_to_add
  user = ${extract{2}{:}{${lookup{$local_part}lsearch{/etc/exim/domains/$domain/passwd}}}}
  group = mail
  return_output
#Restart exim, if service starts, means configuration is successful

Code: Select all

service exim restart
Top

jodumont
Posts: 26
Joined: Fri Jan 05, 2018 3:03 pm

Os: Debian 8x
Web: nginx + php-fpm
Re: Tutorial: Sieve, Managesieve filters with Dovecot and Roundcube.
  • Quote

Post by jodumont » Tue Apr 10, 2018 7:35 am

Hi;

By following these step
and opening the port 4190

it works also for heavy client like Thunderbird or Claws-Mail

Thank for this HowTo :)

Jonathan

PS: I think it will be protected by fail2ban because sieve log into dovecot logs.
Top

liamgibbins
Posts: 28
Joined: Thu Jan 04, 2018 5:33 pm

Os: CentOS 6x
Web: apache + nginx
Re: Tutorial: Sieve, Managesieve filters with Dovecot and Roundcube.
  • Quote

Post by liamgibbins » Mon May 28, 2018 8:28 pm

This is a great tutorial for the community
Top

bruce7890
Posts: 6
Joined: Sun Apr 08, 2018 1:40 pm

Os: Ubuntu 15x
Web: apache + nginx
Re: Tutorial: Sieve, Managesieve filters with Dovecot and Roundcube.
  • Quote

Post by bruce7890 » Wed Sep 19, 2018 7:22 am

plvsouza wrote: ↑
Wed Sep 27, 2017 2:42 am

Updated tutorial to work with centos7 and virtual mail accounts
Does anyone know if this works on Debian/Ubuntu?
Top

gatsukito
Posts: 9
Joined: Thu Jul 21, 2016 9:31 pm

Re: Tutorial: Sieve, Managesieve filters with Dovecot and Roundcube.
  • Quote

Post by gatsukito » Fri Jan 25, 2019 6:00 pm

Good evening.

Today, I have had the same requirement in my VPS, then I have searched and I found one post of this forum in russian that it explains how can I set sieve in dovecot and set filters in roundcube.

viewtopic.php?t=6263

If you need, you can translate it with Google Translate for example.

Tested in Debian 8.11 VPS
Top

mlopez
Posts: 21
Joined: Mon Nov 05, 2018 7:26 am
Contact:
Contact mlopez
Website Twitter

Os: CentOS 6x
Web: apache + nginx
Re: Tutorial: Sieve, Managesieve filters with Dovecot and Roundcube.
  • Quote

Post by mlopez » Sat Apr 27, 2019 1:56 am

Hey,
I've followed the tutorial but I cannot make it work. Settings screen shows filters option but when I click it it shows a 'File not found' error message 'This request has failed: MYDOMAIN.com/webmail/?_task=settings&_action=plugin.managesieve'

Can you help me with this?

I'm using CentOS 7.6.1810 with VestaCP using nginx 1.16, Apache 2.4.6 and Roundcube Webmail 1.4-rc1

Thank you in advance
Top

mlopez
Posts: 21
Joined: Mon Nov 05, 2018 7:26 am
Contact:
Contact mlopez
Website Twitter

Os: CentOS 6x
Web: apache + nginx
Re: Tutorial: Sieve, Managesieve filters with Dovecot and Roundcube.
  • Quote

Post by mlopez » Fri May 03, 2019 11:59 pm

mlopez wrote: ↑
Sat Apr 27, 2019 1:56 am
Hey,
I've followed the tutorial but I cannot make it work. Settings screen shows filters option but when I click it it shows a 'File not found' error message 'This request has failed: MYDOMAIN.com/webmail/?_task=settings&_action=plugin.managesieve'

Can you help me with this?

I'm using CentOS 7.6.1810 with VestaCP using nginx 1.16, Apache 2.4.6 and Roundcube Webmail 1.4-rc1

Thank you in advance
I managed to solve it. The problem is in the file

Code: Select all

/etc/dovecot/conf.d/90-sieve.conf
This directive is deprecated:

Code: Select all

# Directory for :personal include scripts for the include extension. This
  # is also where the ManageSieve service stores the user's scripts.
  #sieve_dir = ~/sieve
  sieve_dir = ~/mail/%d/%n/sieve
  
You just need to change:

Code: Select all

  #sieve = ~/.dovecot.sieve
  sieve = ~/mail/%d/%n/dovecot.sieve
Top

compiz
Posts: 29
Joined: Sat Jul 07, 2018 1:26 pm
Contact:
Contact compiz
Website

Os: CentOS 6x
Web: nginx + php-fpm
Re: Tutorial: Sieve, Managesieve filters with Dovecot and Roundcube.
  • Quote

Post by compiz » Mon Dec 16, 2019 3:18 pm

plvsouza wrote: ↑
Wed Sep 27, 2017 2:42 am

Updated tutorial to work with centos7 and virtual mail accounts

#Install Dovecot Manage Sieve

Code: Select all

yum install dovecot-pigeonhole
#edit 20-managesieve.conf

Code: Select all

nano /etc/dovecot/conf.d/20-managesieve.conf
#Uncomment protocols

Code: Select all

protocols = $protocols sieve
#Edit 10-master.conf

Code: Select all

nano /etc/dovecot/conf.d/10-master.conf
#add auth-master unix-listener to service auth

Code: Select all

service auth {
  unix_listener auth-client {
    group = mail
    mode = 0660
    user = dovecot
  }
  unix_listener auth-master {
    group = mail
    mode = 0660
    user = dovecot
  }
  user = dovecot
}
#Append this to the end of 10-master.conf

Code: Select all

service managesieve-login {
  inet_listener sieve {
    port = 4190
  }
}

service managesieve {
}

protocol sieve {
  managesieve_max_line_length = 65536
  managesieve_implementation_string = dovecot
  log_path = /var/log/dovecot-sieve-errors.log
  info_log_path = /var/log/dovecot-sieve.log
}

plugin {
  sieve = ~/mail/%d/%n/dovecot.sieve
  sieve_global_path = /etc/dovecot/sieve/default.sieve
  sieve_dir = ~/mail/%d/%n/sieve
  sieve_global_dir = /etc/dovecot/sieve/global/
}

lda_mailbox_autocreate = yes

lda_mailbox_autosubscribe = yes

protocol lda {
  mail_plugins = $mail_plugins autocreate sieve quota
  postmaster_address = [email protected]
  hostname = srv.testdomain.com
  auth_socket_path = /var/run/dovecot/auth-master
  log_path = /var/log/dovecot-lda-errors.log
  info_log_path = /var/log/dovecot-lda.log
}

protocol lmtp {
  mail_plugins = $mail_plugins autocreate sieve quota
  log_path = /var/log/dovecot-lmtp-errors.log
  info_log_path = /var/log/dovecot-lmtp.log
}
#edit 90-sieve.conf

Code: Select all

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

Code: Select all

plugin {
  # The path to the user's main active script. If ManageSieve is used, this the
  # location of the symbolic link controlled by ManageSieve.
  #sieve = ~/.dovecot.sieve
  sieve = ~/mail/%d/%n/dovecot.sieve

  # The default Sieve script when the user has none. This is a path to a global
  # sieve script file, which gets executed ONLY if user's private Sieve script
  # doesn't exist. Be sure to pre-compile this script manually using the sievec
  # command line tool.
  # --> See sieve_before fore executing scripts before the user's personal
  #     script.
  #sieve_default = /var/lib/dovecot/sieve/default.sieve

  # Directory for :personal include scripts for the include extension. This
  # is also where the ManageSieve service stores the user's scripts.
  #sieve_dir = ~/sieve
  sieve_dir = ~/mail/%d/%n/sieve
#touch and set the permissions on the log files, else you will get permission errors

Code: Select all

touch /var/log/dovecot-lda-errors.log
chmod 660 /var/log/dovecot-lda-errors.log
chown dovecot.mail /var/log/dovecot-lda-errors.log

Code: Select all

touch /var/log/dovecot-lda.log
chmod 660 /var/log/dovecot-lda.log
chown dovecot.mail /var/log/dovecot-lda.log

Code: Select all

touch /var/log/dovecot-lmtp-errors.log
chmod 660 /var/log/dovecot-lmtp-errors.log
chown dovecot.mail /var/log/dovecot-lmtp-errors.log

Code: Select all

touch /var/log/dovecot-lmtp.log
chmod 660 /var/log/dovecot-lmtp.log
chown dovecot.mail /var/log/dovecot-lmtp.log
#Create default sieve rule

Code: Select all

mkdir /etc/dovecot/sieve
nano /etc/dovecot/sieve/default.sieve

Code: Select all

require ["fileinto"];
# rule:[SPAM]
if header :contains "X-Spam-Flag" "YES" {
  fileinto "Spam";
}

Code: Select all

touch /etc/dovecot/sieve/default.sieve
chmod +w /etc/dovecot/sieve/default.sieve
chown dovecot.mail /etc/dovecot/sieve/default.sieve
#Restart dovecot, if service starts, means configuration is successful

Code: Select all

service dovecot restart
#Configure roundcube

Code: Select all

nano /etc/roundcubemail/config.inc.php

Code: Select all

$config['plugins'] = array(
    'archive',
    'zipdownload',
    'password', 
    'managesieve',
);

// default contents of filters script (eg. default spam filter)
$config['managesieve_default'] = '/etc/dovecot/sieve/default.sieve';
#Configure Exim

Code: Select all

nano /etc/exim/exim.conf

Code: Select all

localuser:
  driver = accept
  #transport = local_delivery
  transport = dovecot
  condition = ${lookup{$local_part}lsearch{/etc/exim/domains/$domain/passwd}{true}{false}}



######################################################################
# TRANSPORTS CONFIGURATION #
######################################################################
begin transports

dovecot:
  driver = pipe
  command = /usr/libexec/dovecot/dovecot-lda -e -d $local_part@$domain -f $sender_address -a $original_local_part@$original_domain
  return_path_add
  log_output = true
  delivery_date_add
  envelope_to_add
  user = ${extract{2}{:}{${lookup{$local_part}lsearch{/etc/exim/domains/$domain/passwd}}}}
  group = mail
  return_output
#Restart exim, if service starts, means configuration is successful

Code: Select all

service exim restart
I have followed your guide to the letter but when i try "service dovecot restart" I get this

"dovecot[28132]: doveconf: Fatal: Error in configuration file /etc/dovecot/conf.d/15-lda.conf line 45: Nested protocol { protocol { .. } } block not allowed
Dec 16 17:12:03 site.eu dovecot[28132]: doveconf: Error: managesieve-login: dump-capability process returned 89
Dec 16 17:12:03 site.eu dovecot[28132]: doveconf: Fatal: Error in configuration file /etc/dovecot/conf.d/15-lda.conf line 45: Nested protocol { protocol { .. } } block not allowed
Dec 16 17:12:03 site.eu systemd[1]: dovecot.service: control process exited, code=exited status=89
Dec 16 17:12:03 site.eu systemd[1]: Failed to start Dovecot IMAP/POP3 email server.
Dec 16 17:12:03 site.eu systemd[1]: Unit dovecot.service entered failed state.
Dec 16 17:12:03 site.eu systemd[1]: dovecot.service failed.
Top


Post Reply
  • Print view

10 posts • Page 1 of 1

Return to “Mail Server”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

Login  •  Register

I forgot my password