e42.uk Circle Device

 

Quick Reference

Dovecot setup with xmail

Dovecot with xmail

I use http://xmailserver.org but I have a number of requirements for imap access... for that I tried courier which is great except that it does not play well with outlook 2010.

Download and Build

To begin, download the sources, configure and make:

./configure --prefix=/opt/dovecot --with-sqlite
make

You will need the sqlite development files installed to perform the configure and compilation.

Configuration

Copy all the default configuration:

cd /opt/dovecot
cp -r share/doc/dovecot/example-config/* etc/dovecot

Add a group and a user for dovecot:

groupadd dovecot
useradd --home-dir /var/empty --shell /bin/false --gid dovecot dovecot

In my case I decided to disable imap, pop3 and pop3s... I don't use them:

file: 10-master.conf
default_login_user = nobody
default_internal_user = dovecot

service imap-login {
  inet_listener imap {
    port = 0
  }
  inet_listener imaps {
    port = 993
    ssl = yes
  }
}

service pop3-login {
  inet_listener pop3 {
    port = 0
  }
  inet_listener pop3s {
    port = 0
  }
}

Alter the 10-ssl.conf file and add the appropriate files, you will need a key a certificate and a dh.pem (dh params file). The comments in the config file are very helpful.

ssl = yes
ssl_cert = </opt/dovecot/bengreen_eu.cert
ssl_key = </opt/dovecot/bengreen_eu.key
ssl_dh = </opt/dovecot/dh.pem

Configure SQL Authentication

Edit the 10-auth.conf file, at the end enable sql authentication:

!include auth-sql.conf.ext

This is also the place to set the default authentication mecanism (see the link in references for more on this).

Change the paths for passdb and userdb in the etc/dovecot/conf.d/auth-sql.conf.ext file so that they are correct. They should be pointing to the dovecot-sql.conf.ext file we will edit next.

Then, dovecot-sql.conf.ext:

driver = sqlite
connect = /opt/dovecot/user.db
default_pass_scheme = PLAIN
password_query = \
  SELECT id AS username, password FROM user WHERE id = '%u'
user_query = \
  SELECT home, uid, gid FROM user WHERE id = '%u'

Then you should make a database file with sqlite and insert some rows:

CREATE TABLE user ( id TEXT, password TEXT, home TEXT,
  uid INTEGER, gid INTEGER, PRIMARY KEY ( id ) ) ;

An example entry might be:

INSERT INTO user VALUES (
  'ben@example.com',
  '{SHA512-CRYPT}$6$xjjE7RGwNjBf0562$m1InWS7qrY/uT6jeKm2L5rclT5gU2yzH9z3Y.qv2ov0mJw2fAKEsThyM8CDeHuOjUe3QhHtT8GxJyOksh0FEa0',
  '/home/ben',
  1000,
  100 );

The password field (the one beginning with {SHA512- was created lie this:

printf 'password\npassword\n' |doveadm pw -s SHA512-CRYPT

For more detail please see the Password Schemes link in References.

Configure passwd-file type Authentication

Rather than create a sqlite database for authentication, use a passwd-style file stored in /etc/dovecot/users. Passwords are created as above:

ben@example.com:{SHA512-CRYPT}...:90:102:::/bin/false::

And alter the 10-auth.conf file to include the passwd file configuration:

!include auth-passwdfile.conf.ext

Configure the Maildir location

Maildir is the directory format used by XMail and a number of other MTAs it works well and is supported by dovecot. The location of the users mail directory can be specified in the passwd file, the SQL database and also by template. The template is defined in 10-mail.conf:

mail_location = maildir:/var/spool/mail/%d/%u

Using the password file above (with a blank home directory location) dovecot would look for the Maildir in /var/spool/mail/example.com/ben@example.com. More detail can be found on the Alpine Linux wiki, see the link in References.

Running the service

As we have opted to put all the executables and config into /opt/dovecot we have to add some things to the path in order to allow the main dovecot process to spawn helpers.

export PATH=/opt/dovecot/sbin:/opt/dovecot/libexec:$PATH
dovecot

To see what is going on look into your syslog output.

Stopping the service

/opt/dovecot/bin/doveadm stop

Simple.

Deleting/Archiving Emails

Use a simple find command to move emails into another Maildir:

find . -name '*,*' -mtime +30 -exec mv {} ../.Archive/cur/ \;

Reference

Quick Links: Techie Stuff | General | Personal | Quick Reference