Home > Computers > mail > courier > Migrating from courier to dovecot | About
Home > Computers > mail > Migrating from courier to dovecot | About
Home > Computers > mail > dovecot > Migrating from courier | About

Too many steps, here they are :

If you have troubles, you may jump directly to troubleshooting

1) install dovecot

apt-get install dovecot-imapd

This will install the IMAP daemon. This is what the MUA talks to to retrive mail (Mail User Agent : your webmail, outlook thunderbird etc.)

apt-get install dovecot-mysql

This is what the imap server will check the passwords against, and optionnally retrieve the maildir location from.

apt-get install dovecot-sieve

Sieve is a filtering language that the dovecot MDA understands (Mail Delivery Agent). Filters can be used to transfer mail to a specific folder according to some criteria that the user chooses, like the sender's email or the subject or any combination of any criteria.

apt-get install dovecot-managesieved

managesieve is a daemon that helps MUA manage filters remotely. The daemon handles operations like create,delete, or update filters on the server. Without this, the user has to has a remote access to the server to do all these operations, vai FTP for SSH for ex.

apt-get install dovecot-lmtpd

This is necessary to deliver emails internally. LMTP is like a lightweight SMTP protocol to deliver emails internally.

2) configure dovecot

You have 9 things to do. First cd to /etc/dovecot/ then :

1) Tell dovecot where to log its useful messages

You should specify a log file yourself :

log_path = /var/log/dovecot.log
debug_log_path = /var/log/dovecot.debug

2) Tell dovecot how to authenticate people

In dovecot-sql.conf.ext, set 'driver = mysql'

In './conf.d/10-auth.cont', set !include auth-sql.conf.ext to tell how to talk to the mysql database and all that.

3) Tell dovecot how to login to the database

In dovecot-sql.conf.ext, set 'connect = host=localhost dbname=mail user=user password=pass'.

Beware : passwords containing white spaces don't work, even with simple or double quotes around them or around the whole connection string.

4) Tell dovecot how to query for the password

In dovecot-sql.conf.ext, set 'password_query = SELECT email as user, password FROM users WHERE email = LOWER('%u')'

set 'default_pass_scheme = SHA256-CRYPT', dovecot can't guess what type of hashing algorithme you're using for your passwords. If that doesn't try other values until you find one. They are documented in http://wiki2.dovecot.org/Authentication/PasswordSchemes

5) Tell dovecot how to locate the maildir for each user

set

userdb {
  driver = static
  args = uid=vmail gid=vmail home=/var/vmail/%d/%n/
}

in './conf.d/auth-sql.conf.ext'. This tells dovecot that the home directory of a user is always /var/vmail/domain/username. Together with the mail_location instruction in ./conf.d/10-mail.conf, dovecot will find the maildir.

Be careful : my vmail id was 113 and I had problems because dovecot thinks that 113 is too low for a valid user id. It could be a system's user with special privileges. So what you need to do is tell dovecot that 113 is safe enough by setting

'first_valid_uid = 100' in 10-mail.conf

set 'mail_location = Maildir:~/ in ./conf.d/10-mail.conf'

In my case I don't have a Maildir directory named "Maildir" but it is named directly after the username, so for example /var/vmail/domain/username is actually a Maildir. So what we do here is simply saying that the home directory of the user IS its Maildir too.

6) Tell dovecot about the folders hierarchy

In courier, folders are not set into hierarchies but are flatten out at the top of the Maildir, with subfolders written in this notation : .Folder.SubFolder.SubSubFolder. The seperator here is ".". At the top of every folder is INBOX. Dovecot needs to know about this.

in './conf.d/10-mail.conf'

set 'separator = .'

set 'prefix = INBOX.'

Don't forget go put a "." separator after INBOX, otherwise you'll get a (possibly silent) error.

7) Tell dovecot that it should love everybody

In './conf.d/10-auth.cont' set the following :

'disable_plaintext_auth=no' It's ok to have plaintext authentication over SSL

'auth_mechanisms = plain login' login should be added as it is needed by MS MUAs (outlook, MS Mail…)

8) Before testing the new setup, convert the old courier-style maildirs to dovecot-style maildirs

Execute this script on the folder you wish to convert. Wait, you didn't have a backup ? YOU DIDN'T HAVE A BACKUP ???. PLEASE, FOR THE LOVE OF ALL THAT IS HOLY, MAKE A BACKUP BEFORE YOU DO THIS. PLEASE. PLEASE.

At this point you should be good to go the for IMAP part

Now we need to cover the mail delivery part

Tell postfix that it should deliver mail through dovecot-lmtp

Set ' virtual_transport=lmtp:unix:private/dovecot-lmtp' in '/etc/postfix/main.cf'

This tells postfix to use dovecot-ltmp to deliver emails to the inboxes.

Set the following configuration in '/etc/dovecot/conf.d/10-master.conf'

service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {
    group = postfix
    mode = 0600
    user = postfix
  }
}

This will create a socket for postfix to connect to and chat with dovecot.

You should also consider setting a quota-status service that would allow postfix to reject mail to overquota mailboxes. See : https://sys4.de/de/blog/2013/04/08/postfix-dovecot-mailbox-quota/

Tell dovecot that it should use the sieve filters when delivering

If you are delivering with lmtp edit '20-lmtp.conf', if you are delivering with dovecot-lda edit '15-lda.conf'

add 'sieve' to the list of plugins like this :

protocol lmtp {
  # Space separated list of plugins to load (default is global mail_plugins).
  mail_plugins = $mail_plugins sieve
}

Tell dovecot that it should enforce quota limits when delivering

in conf.d/10-mail.conf:

mail_plugins = $mail_plugins quota

in conf.d/20-imap.conf:

protocol imap {
  mail_plugins = $mail_plugins imap_quota
}

in conf.d/90-quota.conf

plugin {
  quota = maildir:User quota
}

Now you need to recalculate quotas for each mailbox, use doveadm like this :

root@messagerie[10.10.10.20] ~ # doveadm quota recalc -u a.chaouche@domain.tld

One last thing if you use shared folders

Dovecot needs private and public namespaces. Private namespaces is where the inbox goes, and only the owner gets to read it. Public namespaces is where you want to put the shared folders.

namespace {
  type = private
  separator = /
  prefix =
  #location defaults to mail_location.
  inbox = yes
}

namespace {
  type = shared
  separator = /
  prefix = shared.%%u
  location = maildir:%%h/Maildir:INDEXPVT=~/%%u
  subscriptions = no
  list = children
}

mail_plugins = acl
protocol imap {
  mail_plugins = $mail_plugins imap_acl
}

plugin {
  acl = vfile
}

Troubleshooting

lost connection with host.domain.tld[private/dovecot-lmtp] while receiving the initial server greeting

Check dovecot logs. I had this error :

Apr 27 14:46:58 lmtp(9504): Fatal: Error reading configuration: Invalid settings: postmaster_address setting not given

The solution was to put 'postmaster_address = root@domain.tld in conf.d/15-ldaconf'

imap: Error: Can't load plugin sieve_plugin: Plugin is intended to be used only by binaries: lda lmtp (we're imap)

Remove the sieve plugin from 10-mail.conf and put it in 20-lmtp.conf.

imap: Error: Can't load plugin imap_quota_plugin: Plugin quota must be loaded also (you must set: mail_plugins=$mail_plugins quota)

add quota to mail_plugins in /etc/dovecot/conf.d/20-imap.conf

protocol imap {
  mail_plugins = $mail_plugins imap_quota quota                                  
}

Error: Quota not enabled

root@messagerie[10.10.10.20] ~ # doveadm quota recalc -u a.chaouche@domain.tld
doveadm(a.chaouche@domain.tld): Error: Quota not enabled
root@messagerie[10.10.10.20] ~ # 

Because you need this line in 90-quota.conf

plugin {
  quota = maildir:User quota
}

contact : @ychaouche yacinechaouche at yahoocom


QR Code
QR Code 1) install dovecot (generated for current page)