Install dovecot and then configure it to do imap, pop3 and LDA (Local Delivery Agent).
We need certificates for Dovecot to do secure IMAP and secure POP3 connections. So follow the same steps as we used earlier for Postfix. This time however the certs will be for dovecot. Save these certificate files in a sensible location. I used /etc/dovecot/ssl We'll also be using Dovecot for SASL Authentication. See http://wiki.dovecot.org/HowTo/PostfixAndDovecotSASL for further details, although I have included all the relevant config in my config files.
dovecot.conf
Edit /etc/dovecot.conf
I have included my entire config file below minus the commentary.
## Dovecot configuration file # If you're in a hurry, see http://wiki.dovecot.org/QuickConfiguration # "dovecot -n" command gives a clean output of the changed settings. Use it # instead of copy&pasting this file when posting to the Dovecot mailing list. protocols = lda pop3 pop3s imap imaps protocol imap { listen = 88.198.15.207:143 ssl_listen = 88.198.15.207:993 } protocol pop3 { listen = 88.198.15.207:110 ssl_listen = 88.198.15.207:995 } disable_plaintext_auth = no shutdown_clients = yes log_path = /var/log/dovecot.log info_log_path = /var/log/dovecot-info.log log_timestamp = "%Y-%m-%d %H:%M:%S " ssl = yes ssl_cert_file = /etc/ssl/secmail.uplinkzero.com.signed.crt ssl_key_file = /etc/ssl/secmail.uplinkzero.com.key ssl_ca_file = /etc/ssl/startcom.sub.class1.server.ca.pem ssl_cipher_list = HIGH:!LOW:!SSLv2 mail_location = maildir:/var/vmail/%d/%n mail_privileged_group = vmail mail_debug = no mail_log_prefix = "%Us(%u): " first_valid_uid = 5000 last_valid_uid = 5000 first_valid_gid = 5000 last_valid_gid = 5000 maildir_stat_dirs = no maildir_copy_with_hardlinks = yes maildir_copy_preserve_filename = yes protocol imap { login_executable = /usr/lib/dovecot/imap-login mail_executable = /usr/lib/dovecot/imap imap_logout_format = bytes(i/o)=%i/%o imap_id_log = * } protocol pop3 { login_executable = /usr/lib/dovecot/pop3-login mail_executable = /usr/lib/dovecot/pop3 pop3_uidl_format = %08Xu%08Xv } protocol managesieve { } protocol lda { postmaster_address = postmaster@uplinkzero.com hostname = mail.uplinkzero.com deliver_log_format = msgid=%m subject=%s: %$ sendmail_path = /usr/lib/sendmail rejection_subject = Rejected: %s rejection_reason = Your message to <%t> was automatically rejected:%n%r auth_socket_path = /var/run/dovecot/auth-master } auth_executable = /usr/lib/dovecot/dovecot-auth auth_process_size = 256 auth default { mechanisms = plain login passdb sql { args = /etc/dovecot/dovecot-sql.conf } userdb sql { args = /etc/dovecot/dovecot-sql.conf } user = vmail socket listen { master { path = /var/run/dovecot/auth-master mode = 0600 } client { # This is where we configure SASL path = /var/spool/postfix/private/auth mode = 0660 user = postfix group = postfix } } !include_try /etc/dovecot/auth.d/*.auth } dict { } plugin { } !include_try /etc/dovecot/conf.d/*.conf
dovecot-sql.conf
Next step, edit dovecot-sql.conf so that dovecot knows how to connect to MySQL and what to query.
driver = mysql connect = host=localhost dbname=vmail user=vmail_u password=choose_a_password default_pass_scheme = PLAIN-MD5 password_query = SELECT password FROM postfix_mailboxes WHERE email=concat ('%n', '@', '%d') AND active='1' user_query = SELECT 'maildir:/var/vmail/%d/%n' AS mail, 5000 AS uid, 5000 AS gid FROM postfix_mailboxes WHERE username='%u' AND active='1'
maildirmake.dovecot
Copy the below script into /usr/bin and alias to "maildirmake".
#!/bin/sh # # maildirmake.dovecot -- create maildirs # Copyright (c) 2003, Jaldhar H. Vyas # "Do what thou wilt" shall be the whole of the license. # dir=$1 if [ -z "$dir" ]; then echo "Must supply a directory path" exit 1 fi if [ "$dir" = "-h" ]; then echo "usage: $0 directory" exit 0 fi umask 077 mkdir -p $dir/{cur,new,tmp} || echo "$!" && exit 1 chmod u+rwxg-a- $dir $dir/{cur,new,tmp} || echo "$!" && exit 1 exit 0

