Filter
--------
Configure the Sieve Message Filter
# vi /usr/share/roundcubemail/config/config.inc.php OR vi /var/www/html/roundcubemail/config/config.inc.php
$config['plugins'] = array('archive', 'managesieve', 'password', 'zipdownload');
You can create folders in Roundcube webmail and then create rules to filter email messages into different folders. In order to do this, you need to install the dovecot-pigeonhole package with the following command.
yum -y install dovecot-pigeonhole
yum -y install dovecot*
# vi /etc/dovecot/dovecot.conf
protocols = imap lmtp pop3 sieve
### Add this line Last
service managesieve-login {
inet_listener sieve {
port = 4190
}
service_count = 1
process_min_avail = 1
}
Open the /etc/dovecot/conf.d/15-lda.conf file.
# vi /etc/dovecot/conf.d/15-lda.conf
Scroll to the end of the file, uncomment the mail_plugins line and add the sieve plugin to local delivery agent (LDA).
protocol lda {
# Space separated list of plugins to load (default is global mail_plugins).
mail_plugins = $mail_plugins sieve
}
Save and close the file. If you can find the 20-lmtp.conf file under /etc/dovecot/conf.d/ directory, then you should also enable the sieve plugin in that file like below.
# vi /etc/dovecot/conf.d/20-lmtp.conf
protocol lmtp {
mail_plugins = quota sieve
}
Edit the /etc/dovecot/conf.d/10-mail.conf file.
# vi /etc/dovecot/conf.d/10-mail.conf
Sieve scripts are stored under each user’s home directory. If you followed my PostfixAdmin tutorial and are using virtual mailbox domains, then you need to enable mail_home for the virtual users by adding the following line in the file, because virtual users don’t have home directories by default.
mail_home = /var/vmail/%d/%n
Save and close the file.
By default, Postfix uses its builtin local delivery agent (LDA) to move inbound emails to the message store (inbox, sent, trash, Junk, etc). We can configure it to use Dovecot to deliver emails, via the LMTP protocol, which is a simplified version of SMTP. LMTP allows for a highly scalable and reliable mail system and it is required if you want to use the sieve plugin to filter inbound messages to different folders.
Edit the Dovecot main configuration file.
# vi /etc/dovecot/dovecot.conf
Add lmtp and sieve to the supported protocols.
protocols = imap lmtp sieve
Save and close the file. Then edit the Dovecot 10-master.conf file.
sudo nano /etc/dovecot/conf.d/10-master.conf
Change the lmtp service definition to the following.
service lmtp {
unix_listener /var/spool/postfix/private/dovecot-lmtp {
group = postfix
mode = 0600
user = postfix
}
}
Next, edit the Postfix main configuration file.
# vi /etc/postfix/main.cf
Add the following lines at the end of the file. The first line tells Postfix to deliver emails to local message store via the dovecot LMTP server. The second line disables SMTPUTF8 in Postfix, because Dovecot-LMTP doesn’t support this email extension.
mailbox_transport = lmtp:unix:private/dovecot-lmtp
smtputf8_enable = no
Save and close the file. Finally, restart Postfix and Dovecot.
systemctl restart postfix dovecot
Now you can go to Roundcube webmail, open an email message and click the more button and select create filters to create message filters. For example, I create a filter that moves every email sent from redhat.com to the Red Hat folder.
----Auto reply--------
install Roundcube autoresponder with Dovecot on Centos 7
# vi /usr/share/roundcubemail/config/config.inc.php OR vi /var/www/html/roundcubemail/config/config.inc.php
$config['plugins'] = array('archive', 'managesieve', 'password', 'zipdownload');
# vi /usr/share/roundcubemail/plugins/managesieve/config.inc.php OR vi /var/www/html/roundcubemail/plugins/managesieve/config.inc.php
$config['managesieve_port'] = 4190;
$config['managesieve_host'] = 'localhost';
$config['managesieve_vacation'] = 1;
================ Messages==========================
Subject: On vacation message. I'm on vacation and will not be reading my mail for a while. Your mail will be dealt with when I return.
Troubleshoot Sieve and LMTP
When a sieve filter does not behave as expected, additional logging can be enabled in the # vi /etc/dovecot/config.d/10-logging.conf configuration file. The setting to enable more logging is called “mail_debug”.
# Enable mail process debugging. This can help you figure out why Dovecot # isn't finding your mails. mail_debug = yes
After the above setting is changed, dovecot needs a restart to activate the changes. With the debug setting activated, log entries similar to the ones below can be found in the mail log.
dovecot: lmtp(28422): Debug: none: root=, index=, control=, inbox= dovecot: lmtp(28422): Connect from local dovecot: lmtp(28422): Debug: Loading modules from directory: /usr/lib64/dovecot dovecot: lmtp(28422): Debug: Module loaded: /usr/lib64/dovecot/lib90_sieve_plugin.so dovecot: lmtp(28422): Debug: auth input: mailuser system_groups_user=mailuser uid=500 gid=502 home=/home/mailuser dovecot: lmtp(28422): Debug: changed username to mailuser dovecot: lmtp(28422, mailuser): Debug: Effective uid=500, gid=502, home=/home/mailuser dovecot: lmtp(28422, mailuser): Debug: fs: root=/home/mailuser/mail, index=, control=, inbox=/var/mail/mailuser dovecot: lmtp(28422, mailuser): Debug: kCqdNP+n4VsGbwAAzku34w: sieve: using sieve path for user's script: /home/mailuser/.dovecot.sieve dovecot: lmtp(28422, mailuser): Debug: kCqdNP+n4VsGbwAAzku34w: sieve: opening script /home/mailuser/.dovecot.sieve dovecot: lmtp(28422, mailuser): Debug: kCqdNP+n4VsGbwAAzku34w: sieve: script binary /home/mailuser/.dovecot.svbin is not up-to-date dovecot: lmtp(28422, mailuser): Debug: kCqdNP+n4VsGbwAAzku34w: sieve: script /home/mailuser/.dovecot.sieve successfully compiled dovecot: lmtp(28422, mailuser): Debug: kCqdNP+n4VsGbwAAzku34w: sieve: executing script from /home/mailuser/.dovecot.sieve dovecot: lmtp(28422, mailuser): kCqdNP+n4VsGbwAAzku34w: sieve: msgid=<50c2ff17-7986-3638-9745-1c39b372a0c7@gmail.com>: stored mail into mailbox 'Trash' postfix/lmtp[28079]: A5BC2C0EA1: to=<mailuser@example.com>, relay=mail.example.com[private/dovecot-lmtp], delay=0.36, delays=0.14/0/0.07/0.15, dsn=2.0.0, status=sent (250 2.0.0 <mailuser@example.com> kCqdNP+n4VsGbwAAzku34w Saved)
--------