How To Install & Set Up Dovecot Mail Server With Sieve And Virtual Users

This document describes how to install the Dovecot mail server from source as an imap / pop3 mail server for your domain and how to set up the sieve plugin so your clients can use the sieve mail filtering language for their mail accounts.


1. Get the Sources

We can download Dovecot from I always prefer stable versions so:

wget -c

We also need the sieve plugin source so:

wget -c


2. Install Dovecot

At this point we can continue with the installation of dovecot mail server

tar zxfv dovecot-1.0.13.tar.gz
cd dovecot
make install

And now we need to install the sieve plugin

tar zxfv dovecot-sieve-1.0.2.tar.gz
cd dovecot-sieve-1.0.2
./configure --with-dovecot=../dovecot-1.0.13
make install


3. Configuration

The basic configuration file of dovecot is /usr/local/etc/dovecot.conf and we can create it by doing this:

cp -pi /usr/local/etc/dovecot-example.conf /usr/local/etc/dovecot.conf

The main configuration of dovecot is here :

The below config is a basic configuration file for these features: Imap Protocol, Local Delivery Agent with Sieve plugin, Virtual Users from file and support other programs to authenticate with the dovecot mail server.

# Dovecot configuration file
protocols = imap
listen = *:143
# We can use plain text passwords
disable_plaintext_auth = no
# Logging
log_path = /var/log/dovecot.log
info_log_path = /var/log/
log_timestamp = "%b %d %H:%M:%S "
# SSL settings
# Without ssl
ssl_disable = yes
# Login processes
login_user = dovecot
login_greeting = Hi buddy, have an account ?
login_log_format = %$: %s
# Mailbox locations and namespaces
mail_extra_groups = mail
# Mailbox locations and namespaces
# Clients Inbox at /var/mail, Clients Folders at /var/mail/folders/username/
mail_location = mbox:/var/mail/folders/%u/:INBOX=/var/mail/%u
# Mail processes
mail_debug = yes
mail_log_prefix = "%Us(%u): "
verbose_proctitle = yes
first_valid_uid = 1000
last_valid_uid = 5000
max_mail_processes = 2048
# mbox-specific settings
mbox_read_locks = dotlock fcntl
mbox_write_locks = dotlock fcntl
# IMAP specific settings
protocol imap {
# LDA specific settings
protocol lda {
        postmaster_address = [email protected]
        hostname =
# Sieve plugin for local delivery agent
        mail_plugins = cmusieve
        log_path = /var/log/dovecot-local-deliver.log
        auth_socket_path = /usr/local/var/run/dovecot-auth-master
# Authentication processes
auth_verbose = yes
auth_debug = yes
auth_debug_passwords = yes
auth default {
        mechanisms = plain
        passdb passwd-file {
        # Virtual Users from file
            args = /usr/local/etc/dovecot.passdb
        userdb passwd-file {
        # Virtual Users from file
                args = /usr/local/etc/dovecot.passdb
        user = root
# It's possible to export the authentication interface to other programs:
# For example getmail with MDA external
        socket listen {
          master {
            path = /usr/local/var/run/dovecot-auth-master
            mode = 0660
            user = dovecot
            group = mail

We need to create the configuration file that dovecot reads to authenticate virtual users,


user1:{PLAIN}pass1:1001:1001:User 1 Name:/var/mail/folders/user1:: mail_plugins=cmusieve
user2:{PLAIN}pass2:1002:1002:User 2 Name:/var/mail/folders/user2:: mail_plugins=cmusieve
user3:{PLAIN}pass3:1003:1003:User 3 Name:/var/mail/folders/user3:: mail_plugins=cmusieve
user4:{PLAIN}pass4:1004:1004:User 4 Name:/var/mail/folders/user4:: mail_plugins=cmusieve

Now we are ready to test our imap mail server.


4. Begin & Test Dovecot

To start the dovecot mail server just type:


ps -ef | grep dovecot

If there are any problems just see the log files.

tail -f /usr/local/dovecot*

To verify the config of running dovecot:

/usr/local/sbin/dovecot -n

# 1.0.13: /usr/local/etc/dovecot.conf
base_dir: /usr/local/var/run/
log_path: /var/log/dovecot.log
info_log_path: /var/log/
protocols: imap
listen: *:143
ssl_disable: yes
disable_plaintext_auth: no
login_dir: /usr/local/var/run//login
login_executable: /usr/local/libexec/dovecot/imap-login
login_greeting: Hi buddy, have an account ?
max_mail_processes: 2048
verbose_proctitle: yes
first_valid_uid: 1000
last_valid_uid: 5000
mail_extra_groups: mail
mail_location: mbox:/var/mail/folders/%u/:INBOX=/var/mail/%u
mail_debug: yes
mbox_read_locks: dotlock fcntl
auth default:
  verbose: yes
  debug: yes
  debug_passwords: yes
    driver: passwd-file
    args: /usr/local/etc/dovecot.passdb
    driver: passwd-file
    args: /usr/local/etc/dovecot.passdb
    type: listen
      path: /usr/local/var/run/dovecot-auth-master
      mode: 432
      user: dovecot
      group: mail

If everything till now are running ok, you should check the mail server via telnet. To do this just type the below:

# telnet localhost 143

1 login username password

If you use the above dovecot.conf then you should test it like this:

# telnet 143

1 login user1 pass1

And to check the INBOX:

# telnet 143

* OK Hi buddy, have an account ?
1 login user1 pass1
1 OK Logged in.
2 select inbox
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft $MDNSent $Label1 NonJunk $Forwarded)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft $MDNSent $Label1 NonJunk $Forwarded \*)] Flags permitted.
* 8737 EXISTS
* OK [UIDVALIDITY 1174418788] UIDs valid
* OK [UIDNEXT 112330] Predicted next UID
2 OK [READ-WRITE] Select completed.

And if you want to check that it finds other mailboxes:

# telnet 143

* OK Hi buddy, have an account ?
1 login ebal test
1 OK Logged in.
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft $MDNSent $Label1 NonJunk $Forwarded $Label3 $Label2 $Label4 $Label5 Junk)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft $MDNSent $Label1 NonJunk $Forwarded $Label3 $Label2 $Label4 $Label5 Junk \*)] Flags permitted.
* 8737 EXISTS
* OK [UIDVALIDITY 1174418788] UIDs valid
* OK [UIDNEXT 112330] Predicted next UID
2 OK [READ-WRITE] Select completed.
2 LIST "" *
* LIST (\NoInferiors \UnMarked) "/" "draft"
* LIST (\NoInferiors \UnMarked) "/" "Trash"
* LIST (\NoInferiors \UnMarked) "/" "INBOX"
2 OK List completed.


5. Use Sieve

The Sieve is a Mail Filtering Language and you can find everything here: Dovecot plugin reads the .dovecot.sieve file from our mail location. The above dovecot.conf sets the mail location at /var/mail/folders/usename. So you need to create the file:

touch /var/mail/folders/user1/.dovecot.sieve

According to rfc you can write your rules. An example is here:

require "fileinto";
if header :comparator "i;ascii-casemap" :contains "Subject" "**SPAM**"  {
        fileinto "Trash";

This sieve rule delivers every email where the header subject contains "**SPAM**" to the Trash folder.

If you want to validate your sieve rules here is the perfect project:

If you have apache installed you can set up web mail clients like Horde Groupware Webmail Edition or IlohaMail.

Share this page:

4 Comment(s)

Add comment



I have modify the dovecot.conf and dovecot.passwd for :

  • Pop3 & Imap protocol Supported
  • Folder Indexes
  • Public Sieve Plugin
  • Authentication Cache
  • Encrypted User Passsword with dovecotpw
  • Mbox & Maildir Mailbox Format Supported

Dovecot v1.0.8

Sieve Plugin v1.0.2

From: zeigerpuppy

I am just working through my sieve install, this looks like a good guide, however it may be worth adding support for managesieve, which allows the use of per-user sieve filters controlled by a squirrelmail plugin or even thrunderbird directly.

This needs to be done as is listed here:

by patching the dovecot source first....

will let you know my mileage

From: Shamly


  I have followed you article and installed the dovecot server. it is working fine and user can login to the mailbox. But one problem is that the user cannot access folders such as Draft, Sent, Trash. These folders have not been created automatically. Below is what i get when a user logis in via telnet




what have i done wrong ... Please help


From: fakessh

hi howtoforge


my blog is about the install of version 2.0.0