This documentation is for Dovecot v2.x, see wiki1 for v1.x documentation.
Differences between revisions 15 and 78 (spanning 63 versions)
Revision 15 as of 2007-01-31 10:58:39
Size: 4587
Editor: TimoSirainen
Comment: reversed, use dovecot --exec-mail imap, not imap --exec-mail imap
Revision 78 as of 2019-09-11 14:05:46
Size: 70
Comment: Moved to new doc
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= Mail location =

In configuration file the default mail location is set using `mail_location` setting. This setting used to be called `default_mail_env` in Dovecot versions earlier than 1.0.rc11.

By default `mail_location` is empty, which means that Dovecot attempts to locate automatically where your mails are. This is done by looking at `~/Maildir`, `/var/mail/username` and `~/mail` in that order. It's usually a good idea to explicitly specify where the mails are, even if the autodetection happens to work.

You can use several variables in `mail_location`. A full list of them is in [wiki:Variables Variables], but the most commonly used ones are:

 * `%u`: Full username.
 * `%n`: User part in user@domain, same as %u if there's no domain.
 * `%d`: Domain part in user@domain, empty if there's no domain.
 * `%h`: Home directory.

Typically with maildir it would be set to:

{{{
mail_location = maildir:%h/Maildir }}}

or with mbox:

{{{
mail_location = mbox:%h/mail:INBOX=/var/mail/%u }}}

Use only absolute paths. Even if relative paths would appear to work, they might just as well break some day.

== Index files ==

Index files are by default stored under the same directory as mails. With maildir they are stored in the actual maildirs, with mbox they are stored under `.imap/` directory. You can change these by adding `:INDEX=location` to location string. For example:

{{{
mail_location = mbox:%h/mail:INBOX=/var/mail/%u:INDEX=%h/indexes }}}

== Homeless users ==

Having a home directory for users is highly recommended. [wiki:LDA Deliver]'s Sieve plugin already uses the home directory, and it won't work without one. You could even make the home directory be the same as the mail directory, but this isn't necessarily a good idea, especially with mbox where the created files would show up as mailboxes. If your home and mail directories are the same, you could use:

{{{
mail_location = maildir:%h }}}

If you really don't want to set a home directory, you can simply use something like:

{{{
mail_location = maildir:/home/%u/Maildir }}}

== Per-user mail locations ==

It's possible to override `mail_executable` for specific users by making the [wiki:UserDatabase user database] return `mail` [wiki:UserDatabase/ExtraFields extra fields]. See your specific user database page for more information how to do this. Here are however a couple of examples:

=== SQL ===

{{{
user_query = SELECT home, uid, gid, mail FROM users WHERE user = '%u' }}}

=== LDAP ===

{{{
user_attrs = homeDirectory=home,uidNumber=uid,gidNumber=gid,mailLocation=mail }}}

=== Passwd-file ===

{{{
user:{PLAIN}password:1000:1000::/home/user::userdb_mail=mbox:%h/mail:INBOX=/var/mail/%u }}}

== Mixing mbox and maildir ==

It's possible to use both mboxes and maildirs for the same user with namespaces. See [wiki:Namespaces Namespaces].

Having both mboxes and maildirs mixed within the same namespace isn't currently supported.

== Custom mailbox location detection ==

Dovecot by default detects the mailboxes in this order:

 1. maildir: ~/Maildir
 1. mbox: ~/mail, and /var/mail/%u if it exists
 1. mbox: ~/Mail, and /var/mail/%u if it exists

If you need something else, you can override the `mail_executable` setting to run a script, which sets the MAIL environment properly. For example:

{{{
#/bin/sh

if [ -f $HOME/.maildir ]; then
  export MAIL=maildir:$HOME/.maildir
else
  export MAIL=mbox:$HOME/mail
fi

# Finally execute the imap/pop3. If you use both, you'll need two scripts.
exec /usr/local/libexec/dovecot/imap
}}}

== Only /var/mail mboxes ==

With POP3 it's been traditional that users have their mails only in /var/mail directory. IMAP however supports having multiple mailboxes, so each user has to have a private directory where the mailboxes are stored. Dovecot also needs a directory for its indexes unless you disable them completely.

If you '''really''' want to use Dovecot as a plain POP3 server without index files, you can work around the problem of not having the per-user directory:

 * Set users' home directory to `/tmp` in userdb
 * Modify `mail_location` setting so that the mail root directory is also `/tmp` and append `:INDEX=MEMORY` to it. For example: `mail_location = mbox:/tmp:INBOX=/var/mail/%u:INDEX=MEMORY`
 * Make sure that the users don't have IMAP access, or they can start writing to `/tmp` and accidentally share mail with others users

Instead of `/tmp` directory you can use some other non-writable directory which could be safer.
Moved to https://doc.dovecot.org/configuration_manual/mail_location/

None: MailLocation (last edited 2019-09-11 14:05:46 by MichaelSlusarz)