nav-left cat-right
cat-right

Dovecot

3.11 Dovecot

Dovecot provides POP3, IMAP, or secure versions of either service.

3.11.1 Install Dovecot

The dovecot package that comes with CentOS has MySQL 4 and postgres package dependencies, which I didn't want, which is why it was included at the top of my guide as one of the packages to uninstall. We'll get the latest source from http://www.dovecot.org/download.html and compile it from there.

  • sudo su -
  • mkdir /usr/src/dovecot
  • cd /usr/src/dovecot
  • wget http://www.dovecot.org/releases/1.0/dovecot-[version]
  • tar zxvf dovecot-[version]
  • cd dovecot-[version]
  • ./configure --prefix=/usr/local/dovecot --sbindir=/usr/sbin --sysconfdir=/etc/dovecot
  • make
  • make install

Note that this configure doesn't add any SQL drivers, and auto-detects the SSL libraries.

Dovecot is now installed under /usr/local/dovecot, with the conf file in /etc/dovecot/dovecot-example.conf, which must be renamed to dovecot.conf

3.11.2 Configuring Dovecot

See http://www.howtoforge.com/linux_postfix_virtual_hosting_2 and http://wiki.dovecot.org/QuickConfiguration for more configuration fun. Keep in mind that my set-up uses virtual hosting, so you might not want to follow my configs!

I only serve secure POP3 at the moment, and since I have "virtual" users, I don't need the PAM authentication parts of the configuration. However, because the users are virtual and not real UNIX accounts, we need to set up a users file and a passwords file to verify them when they log in. You'll see all this in the configuration changes I make below:

protocols = pop3s
log_path = /var/log/dovecot
ssl_cert_file = /etc/ssl/mailserver.crt
ssl_key_file = /etc/ssl/mailserver.key
ssl_parameters_regenerate = 48
verbose_ssl = yes
login_max_processes_count = 32
login_greeting = Dovecot ready.
mail_location = mbox:~/mail:INBOX=/var/mail/vhosts/%d/%n
valid_chroot_dirs = /var/mail/vhosts
protocol pop3 {
  login_executable = /usr/local/dovecot/libexec/dovecot/pop3-login
  mail_executable = /usr/local/dovecot/libexec/dovecot/pop3
  pop3_uidl_format = %08Xu%08Xv
}
auth_executable = /usr/local/dovecot/libexec/dovecot/dovecot-auth
auth_verbose = yes
auth default {
  mechanisms = plain digest-md5
}

# passdb pam {
# }

passdb passwd-file {
  # Path for passwd-file
  args = /etc/dovecot/passwd
}

userdb passwd-file {
  # Path for passwd-file
  args = /etc/dovecot/users
}

You'll note that I commented out the passdb pam { section, including the closing brace, and enabled the passdb passwd-file and userdb passwd-file sections. You'll also notice that I set up some SSL options. See the SSL certificate section earlier in the guide where I generated some keys for the mailserver to use.

Now, the following needs to be done to bring our system up to speed with our config file:

  • useradd -r dovecot
  • usermod -s /sbin/nologin dovecot
  • touch /etc/dovecot/users
  • touch /etc/dovecot/passwd

The users file needs to be in the same format as the standard system passwd file (/etc/passwd). The dovecot passwd file also uses the standard system passwd file format to encrypt passwords. This means that in order to generate passwords, you need a tool that utilizes the basic crypt() system call. I couldn't find anything to do it because I'm a total noob, so I wrote a php script called make_md5crypt_password that just called it:


#!/usr/local/bin/php
<?php

echo crypt($argv[1]);

?>

I'm sure there's a better way, but that's what I did for now. Simply run it like ./make_md5crypt_password.php mypassword, and it'll output a password suitable for copying and pasting into the dovecot passwords file.

When you're done, you'll have a dovecot users file that looks something like this:

blake@mydomain.com::5000:5000::/var/mail/vhosts/mydomain.com/:/bin/false::
user2@mydomain.com::5000:5000::/var/mail/vhosts/mydomain.com/:/bin/false::

And a dovecot passwd file that looks something like this:

blake@mydomain.com:$1$zEnY/vfZ$u2aC34HRkx7XrZ4GTT7dU0
user2@mydomain.com:$1$7TAORxMd$3y/PMe5fGO7lodxLdpJLE.

Finally, to set dovecot up as a service, we'll apply a standard init.d script to it. A copy of such a script can be found at http://wiki.dovecot.org/DovecotInit. Copy it to /etc/init.d/dovecot, and change the DAEMON=/usr/local/sbin/dovecot line to DAEMON=/usr/sbin/dovecot. Then put the following at the top of the file:

#! /bin/sh
# Startup script for the Dovecot mail daemon
#
# chkconfig: 2345 82 29
# description: Dovecot is a mail serving daemon with POP3/IMAP services.
# processname: dovecot

Hooray! Another service controlled via the service command. Add it to chkconfig (so it'll start at boot time), then start 'er up:

  • chkconfig --add dovecot
  • service dovecot start

Log out of your root session and take a break.

  • Digg
  • del.icio.us
  • DotNetKicks
  • Slashdot
  • StumbleUpon