This documentation is for Dovecot v1.x, see wiki2 for v2.x documentation.

This describes how to install and configure Dovecot with LDAP authentication. This is not the definitive guide to installing Dovecot or OpenLDAP. I am not an expert on IMAP, e-mail, LDAP, or Unix. As I was writing this, I discovered unexpected quirks in OpenLDAP that caused my configuration to do things I hadn't intended. I succeeded in installing Dovecot only with help from Timo, and I made a number of mistakes in the process. There may be mistakes in this document. It is, however, based on a working configuration.


FreeBSD 4.8 openldap-2.1.22 dovecot-0.99.10


This sets up mail accounts for people who don't have accounts on the FBSD box; i.e. there is a mail account for ole_wobble in the LDAP registry, but no matching account in the Unix passwd file. However, each mail account does require its own directory in /var/mail; e.g. for user Ole Wobble Olson, you need the directory /var/mail/ole_wobble. There is a Unix account named postoffice which handles all administrative tasks and owns the directories and files set up for mail accounts in /var/mail. The group for files in /var/mail is mail. Using ole_wobble as an example:

Mail storage is mbox, but these instructions should work fine with Maildir directories. The UID number for the postoffice account is 3000 and the GID number is 8. Change the ID numbers to match your system.

In each user directory in /var/mail, I create three files: inbox, outbox, and Trash. These are needed for the MUAs (mail clients) we use. Eudora requires the inbox to be "inbox", all lower case; mutt requires the outbox to be "outbox", all lower case, and Eudora uses a trash box named "Trash".

If you want to use raw logging, you will need to add a directory named "dovecot.rawlog" to /home/postoffice.


The OpenLDAP instructions are *extremely* sketchy and are intended only to supplement the instructions at the OpenLDAP web site. They give information specific to a Dovecot setup that is missing from the OpenLDAP manual.

If you have portupgrade installed, the simplest way to install OpenLDAP is by using the portinstall tool.

The instructions for configuring OpenLDAP, including a Quick Install Guide, are at

OpenLDAP appears to be difficult to install properly. My first two attempts were unsuccessful. The FreeBSD port includes Pearl scripts that run tests to ensure that the installation succeeded. Even though the installation passed the tests, it couldn't be configured to work properly. You may need to install a few times before you get a usable installation of OpenLDAP.

Go to /usr/local/etc/rc.d, and copy to (Yes, that's the startup file for the slap daemon.) Open the file in a text editor. Ignore the line that says

Comment out the line that says

Save your changes and close the text editor.

Go to the directory containing the OpenLDAP configuration files.

Make a copy of slapd.conf.default and name it slapd.conf. Open slapd.conf in a text editor. You will need the the following lines to reference the schemas you need:

The following line will set the default password hashing method to the CRYPT algorithm, which is compatible with Dovecot:

The Quick Install Guide at the OpenLDAP explains how to set up an administrator with global rights on the LDAP registry, and how to add entries. Here is a data hierarchy in ldif format that can be used to provide Dovecot mail accounts. You should be able to copy it into an ldif file, modify it for your own use, and install it all at once.

The expression "dc=wibble,dc=net" should match the suffix setting in slap.conf.

If you plan to install this by copying it to a file and running ldapadd, you must retain the blank lines between the entries.

The uidNumber is set to the uid number of the postoffice account. The gidNumber is set to the gid number of the mail group. The homeDirectory is set to the home directory of the postoffice account. This allows the raw log function to write to that directory. If you don't include the homeDirectory attribute, you will have to apply a patch to Dovecot. The patch is described below, in the Installing Dovecot section. The use of the posixAccount object class requires that you use the uid, cn, uidNumber, gidNumber, and homeDirectory attributes (and therefore shouldn't need the patch).

The home directory is always set to the home directory of the postoffice account. This allows writing raw logs to the postoffice home directory.

To insert the entries above, save them in a file named wibble.ldif. Run ldapadd from the command line:

Don't include the backslash; it just indicates that the two lines are actually one line.

Returning to slap.conf, the following will give dovecot read access to the entries in the ou=accounts section, but no write access and no access to other parts of the registry.

This is enough to allow Dovecot to authenticate mail users and itself.

The final step in setting up your LDAP registry is to add the passwords. Every account in the ou=accounts section will need one. Assuming that you've slavishly imitated the example in the Quick Install Guide at the OpenLDAP site and called your LDAP administrator "Manager", you can add passwords from the command line with

for the dovecot user and

for mail accounts. The -S option prompts you for the new password, and the -W option prompts you for the LDAP Manager password.

You can view the finished registry with

Installing Dovecot

Again, the simplest approach is the portinstall tool. If you don't include homeDirectory info with your all your LDAP entries, you will need a patch. Download the patch from

To apply the patch, go to /usr/ports/mail/dovecot. If you've previously installed dovecot and still have the work directory, you need to remove it.

Then you need to recreate the work directory.

Go to the directory containing the file you need to patch.

Copy auth-no-homedir.patch (the patch file you downloaded) to this directory. Now run patch.

If you get no error messages, you can proceed with the installation. If you do get error messages, you will need to apply the patch by hand. Open auth-no-homedir.patch in a text viewer. The file you need to patch is listed in the first line of auth-no-homedir.patch. Open that file in a text editor in another ttyv or xterm.

The path file contains two contiguous lines, the first beginning with a "-" and the second beginning with a "+". The first is the line you will delete from the file to be patched, and the second is the line that will replace it; i.e. subtract the "-" line and add the "+" line. Immediately surrounding the two lines are the context lines; three above and three below. Search for the line in the file to be patched that matches the "-" line *and* has the same context lines above and below. When you find this line, delete it and replace it with the "+" line in the patch file. (Do not include the "+" marker.) Double check that you have deleted only what needs to be deleted and added only what needs to be added. Save the file and close the text editor and text viewer. Delete auth-no-homedir.patch.

Once you have successfully run patch or patched by hand, return to /usr/ports/mail/dovecot. Open the Makefile in a text editor. Find the line that begins with "CONFIGURE_ARGS+=". If you don't have the following two arguments, add them.

Raw logging isn't necessary, but it can be useful. You have to have the --with-ldap argument to enable Dovecot to work with LDAP.

If you remove support for alternative authentication methods (PAM, PGSQL, etc), you should leave support for passwd. When I was debugging my configuration, I found it helpful to switch between passwd and LDAP authentication. If my setup worked with passwd and not with LDAP, then I knew that I needed to look at Dovecot's LDAP configuration, or at OpenLDAP.

Save your changes to Makefile, and close the editor.

Now you're ready to install.

If make completes and registers Dovecot without giving error messages, then your installation was successful.

Configure Dovecot

To start Dovecot automatically when you boot, go to /usr/local/etc/rc.d and copy to

Go to /usr/local/share/doc/dovecot and copy dovecot-ldap.conf to the /usr/local/etc directory. Go to the /usr/local/etc directory and open dovecot-ldap.conf in a text editor.

The first setting is

If Dovecot and OpenLDAP are running on the same machine, then this is fine. If you have OpenLDAP running on a different machine, you will need to set this to the name of the LDAP machine.

This is set to the Distinguished Name that identifies the Dovecot entry in your LDAP registry.

Set this to the password you assigned dovecot using the ldappasswd command.

'Nuff said.

This tells Dovecot where to search in your LDAP registry. Dovecot will search for passwords and UIDs in the entries that fall below ou=accounts in the data hierarchy.

If you are referencing and dereferencing aliases, then you know a lot more about LDAP than I do.

This tells Dovecot to search all entries that fall below the base entry. If it were set to "onelevel", Dovecot would search only entries one level below the base entry. If it were set to "base", Dovecot would search only the base entry.

From an e-mail that Timo sent to the list:

If you have set up your LDAP registry so that it doesn't supply homeDirectory, uidNumber, and gidNumber (which means that you've applied the homeDirectory patch, you're not using raw logging, you've set default values for uid and gid in this config file, and your LDAP entries don't use the posixAccount object class), you can try the following:

I haven't tried it, so I can't promise that it works. If you change the default setting, don't remove any of the commas.

Specifies which class to search in a given entry, and to find the uid that matches the user name passed by the mail client.

Which attributes to use when matching passwords.

Specifies which class to search in a given entry, and to find the uid that matches the user name passed by the mail client.

If you leave this commented out, Dovecot will automatically detect that OpenLDAP is using CRYPT.

This provides a default UID number for LDAP entries that lack the uidNumber attribute. If you use the posixAccount object class in your LDAP registry, you can't enter data for an account without providing a uidNumber and gidNumber, so this and the next setting aren't necessary.

While still in /usr/local/etc, open dovecot.conf in a text editor.

This was created for you during installation.

You can add other protocols if you want. This setup only uses IMAP.

You don't need to specify port 143; I just like to be specific. According to the documentation, * causes Dovecot to listen on all available IP4 interfaces. If your IMAP box is also your Internet gateway, and you're not offering mail services externally, then you probably don't want that. You can specify your LAN interface and Dovecot will continue to listen at localhost. If your host name isn't exposed externally, then you can use

Otherwise use

If you have this set to yes, you can ignore the SSL setting that follow in dovecot.conf.

The above are all part of the default conf file.

If you are assigning the postoffice UID number to all mail accounts, you can restrict access to only that UID number.

Since all mail accounts are assigned the mail group's number...

Another default conf file setting.


This tells Dovecot where the mail for a given account is located. Dovecot replaces "%u" with the account name. For the two user accounts in the ldif data hierarchy given above, "%u" would expand to ole_wobble and ole_wubble.

We don't use Outlook or Outlook Express. However, someone may decide to use an MS mail client in the future, and leaving this in place does no harm.

My IMAP box really doesn't work very hard, so I don't think it matters how this is set. If your mail server gets hammered regularly, you may want to play with this and see if it makes a difference in speed.

Another performance tweak that doesn't matter to me, but may matter to you. "yes" is supposed to be faster.

I also tried flock and dotlock, and they work FBSD. This is the preferred setting, if it works on your system.

More default conf file settings.

"plain" seems more likely to work under more circumstances.

If you need to switch to passwd authentication for testing, change this to

The comments in dovecot.conf make it look like there's supposed to be a colon in there, but this is the correct form.

More default conf file settings.

If you need to switch to passwd authentication for testing, change this to

If you have to debug your configuration, you'll want as much information as possible.

MUAs (aka mail clients)


In your .muttrc file:


For some reason, when using mbox files, Eudora looks for a file named "inbox" (all lower case) to use as the IMAP inbox. If you name it "Inbox", Eudora won't be able to find it.

For equally obscure reasons, Eudora lists all IMAP mailboxes under the Dominant personality.

Eudora 4.2.

Go to Special->Settings->Getting Started. Enter information in all the text boxes. Go to "Hosts". The Mail host name should have carried over. Fill in the SMTP host name.

Go to "Checking Mail" Click on IMAP. Click on "Check mail every X minutes" and type in 15 (or whatever). Whenever Eudora checks the server for new mail, a window pops up in the middle of what you are doing and announces that you have or don't have new mail. This can get extremely irritating, so you may not want to check this. Leave "IMAP Mailbox Location Prefix" blank. Click on "Use minimal headers", "Use background threading", and "Save password". Unselect "Send on check".

Go to "Sending Mail" and fill in any missing information. Go to "Personality Extras" and click on "Use a trash mailbox on the IMAP server". The first time you delete an e-mail, you should get a message asking you to select a trash mailbox from the Mailbox menu. Go to Mailbox->Dominant and select Trash.

Eudora 5.1. Go to Tools->Options->Getting Started. Enter information in all the text boxes. Go to "Checking Mail". The IMAP server name and your account name should have carried over. Click on "Remember Password".

Go to "Incoming Mail". Click on IMAP at the top. Leave "IMAP Mailbox Location Prefix" blank. The documentation says you need something there, but you don't. Select "Minimal Headers Only". Under "When I delete a message:", click on "Move it to:". Click on the Trash button, and select the Trash box under Dominant. If there is no Trash box under Dominant, then go to Tools->Mailboxes. In the Mailbox window, right click on Dominant, and click on "Refresh Mailbox List". If you've added a Trash file in your /var/mail directory, the Trash mailbox will show up under Dominant. Try the Trash button again, and select the Dominant Trash mailbox.

Go to "Sending Mail". Click on "Immediate Send". Unselect "Send on check". You don't have to do that, but I find that "Send on check" results in mail being sent before I'm ready to send it.

Go to "Miscellaneous" (last). Click on "Empty trash when exiting". Or if you're one of those people who use the trash as a To-Do box, don't click on "Empty trash when exiting".