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

Want to support HowtoForge? Become a subscriber!
 
Submitted by ebal (Contact Author) (Forums) on Wed, 2007-09-05 12:27. :: Email

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 http://dovecot.org. I always prefer stable versions so:

wget -c http://dovecot.org/releases/1.0/dovecot-1.0.13.tar.gz

We also need the sieve plugin source so:

wget -c http://dovecot.org/releases/sieve/dovecot-sieve-1.0.2.tar.gz

 

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
./configure
make
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
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 : http://wiki.dovecot.org/MainConfig

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
base_dir=/usr/local/var/run/
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/dovecot.info.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 = root@mydomain.org
        hostname = mydomain.org
# 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,

/usr/local/etc/dovecot.passdb

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:

/usr/local/sbin/dovecot

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/dovecot.info.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
  passdb:
    driver: passwd-file
    args: /usr/local/etc/dovecot.passdb
  userdb:
    driver: passwd-file
    args: /usr/local/etc/dovecot.passdb
  socket:
    type: listen
    master:
      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 mydomain.org 143

1 login user1 pass1

And to check the INBOX:

# telnet mydomain.org 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
* 0 RECENT
* 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 mydomain.org 143

* OK Hi buddy, have an account ?
1 login ebal test
1 OK Logged in.
2 SELECT INBOX
* 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
* 0 RECENT
* 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: http://tools.ietf.org/html/rfc3028. 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";
        stop;
}

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:http://libsieve-php.sourceforge.net/.

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

6. Usefull Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by fakessh (not registered) on Sun, 2010-08-29 17:51.

hi howtoforge

 

my blog is about the install of version 2.0.0

http://fakessh.eu/?tag=la-config-de-mon-postfix-et-de-mon-devocot

http://fakessh.eu/?p=150
Submitted by Shamly (not registered) on Tue, 2010-02-02 07:16.

Hi,

  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

 

. OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS MULTIAPPEND UNSELECT IDLE CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS] Logged in

 

what have i done wrong ... Please help

 

Submitted by zeigerpuppy (not registered) on Tue, 2008-10-28 12:31.

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:

http://wiki.dovecot.org/ManageSieve

by patching the dovecot source first....

will let you know my mileage

Submitted by ebal (registered user) on Wed, 2007-12-05 09:45.

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

http://ebalaskas.gr/wk/dovecot

Dovecot v1.0.8

Sieve Plugin v1.0.2