This site is now 100% read-only, and retired.

Setting up an IMAP server with dovecot

Posted by Steve on Thu 20 Oct 2005 at 11:33

This brief introduction to setting up an IMAP mailserver. The big attraction of using an IMAP mail-server is that all folders, and state, is persisted upon the server side. So if you login to check your mail from multiple locations you always have the same view of it.

Once you have the IMAP server running you can setup webmail to allow you to check your mailboxes without having to setup a client - or access your mail when you're on the move.

Dovecot is a reatively new server, but it has proven both small, fast, and reliable. It offers both an IMAP server component and a POP3 server. Here we'll only be covering the former.

Installing the package is simple enough. Simply run:

apt-get install dovecot-imapd

Once installed you'll be able to configure the server by means of the files in the directory /etc/dovecot/.

The main configuration file we will touch is the file /etc/dovecot/dovecot.conf. Firstly we need to enable the IMAP server by changing the default lines:

# Protocols we want to be serving:
#  imap imaps pop3 pop3s
protocols =

As we only care about IMAP here, rather than POP3, we can set:

# Protocols we want to be serving:
#  imap imaps pop3 pop3s
protocols = imap imaps

If you have special needs you can also choose to allow the server to only listen upon a specific address. (For my needs I wish to later install Webmail, so I don't wish to make the server publically available). As an example you can cause the server to only listen upon the loopback address with:

# IP or host address where to listen in for connections. It's not currently
# possible to specify multiple addresses. "*" listens in all IPv4 interfaces.
# "[::]" listens in all IPv6 interfaces, but may also listen in all IPv4
# interfaces depending on the operating system. You can specify ports with
# "host:port".
imap_listen = localhost
#pop3_listen = *

# IP or host address where to listen in for SSL connections. Defaults
# to above non-SSL equilevants if not specified.
imaps_listen = localhost
#pop3s_listen = 

The next thing you'll need to do is tell dovecot where it can find the mailboxes for the local users. Here you have several options, and which you choose will depend upon the mail setup you have upon your host.

For my servers I tend to use the mbox mail-store - where each user has a directory ~/Mail containing a file for each of their mailboxes.

If you have the same setup you can use the following configuration:

default_mail_env = mbox:~/Mail/

The other options are discussed in the configuration file as this section of the configuration file shows:

# Default MAIL environment to use when it's not set. By leaving this empty
# dovecot tries to do some automatic detection as described in
# /usr/share/doc/dovecot-common/mail-storages.txt. There's a few special 
# variables you can use:
#
#   %u - username
#   %n - user part in user@domain, same as %u if there's no domain
#   %d - domain part in user@domain, empty if user there's no domain
#   %h - home directory
#
# You can also limit a width of string by giving the number of max. characters
# after the '%' character. For example %1u gives the first character of
# username. Some examples:
#
#   default_mail_env = maildir:/var/mail/%1u/%u/Maildir
#   default_mail_env = mbox:~/mail/:INBOX=/var/mail/%u
#   default_mail_env = mbox:/var/mail/%d/%n/:INDEX=/var/indexes/%d/%n
#

With these changes made we can now restart the server, and cause the IMAP server to run:

/etc/init.d/dovecot stop
/etc/init.d/dovecot start

Once the server is started you can use any IMAP-capable mail client to test that things are working. mutt is a good choice if you're testing on a loopback installation.

Simply run:

mutt -f imap://username@localhost/folder

Once mutt has prompted you for your password you should see your selected folder.

If the test succeeds you can now go on to setup webmail with SuirrelMail.

 

 


Re: Setting up an IMAP server with dovecot
Posted by Anonymous (213.164.xx.xx) on Thu 20 Oct 2005 at 13:04
dovecot is nice, but it has one feature missing that courier-imap has: shared imap mailboxes. In courier, multiple people can use a single mailbox, dovecot has this feature in 1.0 which is beta, and not in sarge.

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by Steve (82.41.xx.xx) on Thu 20 Oct 2005 at 13:22
[ View Weblogs ]

Interesting comment, thanks. I can see how shared access would be very useful for some jobs - such as a shared "support" mailbox for example.

I guess we'll just have to wait for it to become stable and then released. I'm sure that apt-get.org, or the backports site will carry it when it's ready.

Steve
--

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by hardik (61.95.xx.xx) on Thu 20 Oct 2005 at 13:11
Steve, If you don't mind but apt-get install dovecot-imap is not working
with my debian repository that is ............
-------------------------------------------------
deb http://http.us.debian.org/debian stable main
-------------------------------------------------

I have search, it is dovecot-imapd.

So, Below will work.
---------------------------------------
apt-get install dovecot-imapd
---------------------------------------

Cheers,
Hardik Dalwadi.

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by Anonymous (202.164.xx.xx) on Mon 14 Nov 2005 at 11:05
I had to change dovecot.conf to "default_mail_env = maildir:/home/%u/.maildir/" before it would create mail folders/files.

Now I can send emails using a mail reader ( thunderbird - imap ), and can add folders and rename them, the sent posts go to the sentbox, but I cannot get emails? any suggestions appreciated.

When I;

mutt -f imap://dannyr@localhost/.maildir

I get the next option;

/home/dannyr/Mail does not exist. Create it? ([yes]/no):

mynote:Mail - shouldn't it be looking in .maildir. If I change the line to be Mail - I still don't get mail?
----------------------------------------
next message:
This certificate belongs to:
ns1.realtek.net.au root@realtek.net.au
Dovecot mail server
ns1.


This certificate was issued by:
ns1.realtek.net.au root@realtek.net.au
Dovecot mail server
ns1.


This certificate is valid
from Mon, 14 Nov 2005 05:41:00 UTC
to Tue, 14 Nov 2006 05:41:00 UTC
SHA1 Fingerprint: E449 1059 1414 FFED 76AC 3326 CFFD 507C 73E7 79DB
MD5 Fingerprint: 4208 FA87 8F6A AC82 71B7 EE73 9ECA 9064

WARNING: Server hostname does not match certificate
---------------------------------------------------
the "/etc/hostname" is ns1.realtek.net.au

Is there something wrong with my certificates?

Danny Regan




[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by dregan (202.164.xx.xx) on Mon 14 Nov 2005 at 11:15
I had to change dovecot.conf to "default_mail_env = maildir:/home/%u/.maildir/" before it would create mail folders/files.

Now I can send emails using a mail reader ( thunderbird - imap ), and can add folders and rename them, the sent posts go to the sentbox, but I cannot get emails? any suggestions appreciated.

When I;

mutt -f imap://dannyr@localhost/.maildir

I get the next option;

/home/dannyr/Mail does not exist. Create it? ([yes]/no):

mynote:Mail - shouldn't it be looking in .maildir. If I change the line to be Mail - I still don't get mail?
----------------------------------------
next message:
This certificate belongs to:
ns1.realtek.net.au root@realtek.net.au
Dovecot mail server
ns1.


This certificate was issued by:
ns1.realtek.net.au root@realtek.net.au
Dovecot mail server
ns1.


This certificate is valid
from Mon, 14 Nov 2005 05:41:00 UTC
to Tue, 14 Nov 2006 05:41:00 UTC
SHA1 Fingerprint: E449 1059 1414 FFED 76AC 3326 CFFD 507C 73E7 79DB
MD5 Fingerprint: 4208 FA87 8F6A AC82 71B7 EE73 9ECA 9064

WARNING: Server hostname does not match certificate
---------------------------------------------------
the "/etc/hostname" is ns1.realtek.net.au

Is there something wrong with my certificates?

Danny Regan



[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by simonw (84.45.xx.xx) on Thu 20 Oct 2005 at 18:25
[ View Weblogs ]
Dovecot supported shared folders fine, it doesn't support IMAP namespaces so it can't do it within one mail account (like UWIMAP or Courier can).

If you need to share a set of folders, you still need to create an account for it, and add that to all the mail clients that need to share.

On the other hand for a fast, secure, easily configured IMAP server I'm happy to make that sacrifice.

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by jeld (24.39.xx.xx) on Thu 20 Oct 2005 at 15:51
default_mail_env = mbox:~/Mail/
Why would you want to use mbox when you have a choice :)
In my home setup, I use
default_mail_env = maildir=/home/%u/.maildir

You are off the edge of the map, mate. Here there be monsters!

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by Steve (82.41.xx.xx) on Thu 20 Oct 2005 at 15:56
[ View Weblogs ]

It is simpler for me to work with, usable without problems in environments where decent locking is available and scales reasonably well for "small" mailboxes.

I feel a holy war coming on - use what is best for you!

Steve
--

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by simonw (84.45.xx.xx) on Thu 20 Oct 2005 at 18:40
[ View Weblogs ]
> I feel a holy war coming on - use what is best for you!

Dovecot prefers maildir - trust me on that. I see a few problems with the Trash folders (presumably because they are "hot" folders) where I use it with mbox, no such problems where maildir is used (Okay that is Redhat 7 with a source compiled dovecot IIRC, but the dovecot mailing list has two types of users, happy users, and mbox users).

Okay ">Trash" isn't a challenging command, but if you have other users besides you....

For the record I'm on the maildir side of the Holy War, seen too many (otherwise) promising email programs get one line wrong in an mbox.

The latest Dovecot code has addressed most or all of the issues with mbox, but that isn't in Sarge.

PS: mailenv has some interest "defaults" which mean you may get away with just adding in the "protocols=" line, for system admin who don't like to think ;)

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by jeld (24.39.xx.xx) on Thu 20 Oct 2005 at 19:11
No, I don't wanna start a war, so I will comment on a problem I encountered with dovecot + maildir.

Problem: Once in a while I found that dovecot mysteriously forgets that .maildir is the INBOX and creates an .INBOX subfolder. After that (obviously) all the other subfolders and the mail become unavailable. Removing the extra inbox and restarting dovecot usually helps, but still annoying.

On the other hand, dovecot is the only IMAP server I found that allows creating folders at the same level as Inbox.

You are off the edge of the map, mate. Here there be monsters!

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by Anonymous (84.178.xx.xx) on Fri 21 Oct 2005 at 00:07
Try Cyrus-Imapd. It easily manages the creation of folders at Inbox level by using the altnamespace attribute. It also supports sharing of folders within user mailboxes. It comes with its own mail format, but that turns out to be an advantage if you don't require compatibility with other mail servers... Cyrus mail format is safe and fast due to indexing. Oh and Cyrus supports server-side filtering thanks to sieve support.

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by undefined (192.31.xx.xx) on Fri 21 Oct 2005 at 01:02
what's a good way to have user's maintain filters using seive?

i currently use procmail, but i would prefer seive as it is a "standard".

but if i have to ssh into the server to edit my sieve filters, there's no practical benefit of it over procmail.

as seive is a rfc standard (i think i'm remembering correctly) i figured a php web interface would be available, but i didn't see one last time i researched seive a month or so ago.

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by Anonymous (84.178.xx.xx) on Fri 21 Oct 2005 at 08:56
Install the Horde Framework. Horde comes with Ingo, a great PHP-based application that blends in IMP to allow users to use Sieve-based filters.

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by simonw (84.45.xx.xx) on Sat 22 Oct 2005 at 13:04
[ View Weblogs ]
Squirrelmail has Sieve plugins, but I haven't deployed any yet, so can't comment further.

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by Anonymous (81.226.xx.xx) on Sat 22 Oct 2005 at 13:11

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by ivc (212.125.xx.xx) on Sun 23 Oct 2005 at 23:06
There's also a dedicated sieve web-admin tool called websieve.

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by Anonymous (130.83.xx.xx) on Wed 9 Nov 2005 at 14:25
There is also smartsieve, which is a descendant of websieve (IIRC). I'm happy with it and it has a friendly and responsive author.

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by Anonymous (84.194.xx.xx) on Fri 21 Oct 2005 at 08:49
Has anyone used the dovecot POP & IMAP server for virtual mailboxes stored in a (MySQL) database?

I'm using something like described in "Courier POP3 and IMAP authentication" of SASL2 Courier-authdaemon authentication for Postfix2 on Debian, using authmysql of the courier-imap server.

I think most people setting up IMAP servers are people with virtual users. Only a little percentage of mailboxes need a shell account.

Fred

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by simonw (84.45.xx.xx) on Sat 22 Oct 2005 at 13:09
[ View Weblogs ]
No but I've followed (actually reinvented) the Dovecot wiki explanation of how to do this with Postgresql, and got two servers in configurations similar to this. The Wiki explanation was excellent, although I find such configurations are fiddly compared to /etc/passwd, when you want to do clever stuff, but essential when you want to sensibly maintain "paul@example.com" and "paul@example.net" as different users (creating paul, and paul1, and redirecting one to other is just madness IMHO).

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by Anonymous (150.101.xx.xx) on Fri 21 Oct 2005 at 09:19
Any idea on how quotas could be applied to Dovecot mailboxes with a MailDir setup?

I dont mean via the FS, I mean something along the lines of how Cyrus does it. (At least I think Cyrus can do it.)

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by Anonymous (61.9.xx.xx) on Wed 16 Nov 2005 at 03:54
I did get dovecot working with imap and then with pop3 - a real treat.

BUT: I had to do the following for Maildir's & and logging;

1. Edit /etc/dovecot.conf ;
protocols = imap imaps pop3

imap_listen = *
pop3_listen = *
default_mail_env = maildir:/home/%u/Maildir/

2. Edit /etc/postfix/main.cf
#mailbox_command = procmail -a "$EXTENSION"
mailbox_command = /usr/bin/procmail -a "$USER"

3. Create a /etc/procmailrc file (I did not need .procmailrc)
SHELL=/bin/sh PATH="$HOME/bin:/usr/bin:/usr/local/bin:/usr/include: ;
/usr/local/sbin:/bin:/sbin:/usr/sbin"
LOCKFILE=$HOME/lockfile.lock
#ASSASSINLOCK=$HOME/assassin.lock
DEFAULT=$HOME/Maildir/
JUNKMAIL=$HOME/Maildir/.junkmail/
TRASH=$HOME/Maildir/.Trash
#NEWBIE=$HOME/Maildir/.LinuxNewbie/
#EXPERT=$HOME/Maildir/.LinuxExpert/
VIRUS=$HOME/Maildir/.virus/
BITBUCKET=/dev/null
LOCKTIMEOUT=10
#LOGFILE=/tmp/procmail_log
LOGFILE=$HOME/logs/procmaillog
#LOGABSTRACT=no
#VERBOSE=no

4. Edit /etc/skel;
drwxr-xr-x 4 root root 4096 2005-11-16 10:24 .
drwxr-xr-x 113 root root 8192 2005-11-16 10:26 ..
-rw-r--r-- 1 root root 567 2004-12-20 03:53 .bash_profile
-rw-r--r-- 1 root root 1834 2004-12-20 03:53 .bashrc
drwxr-xr-x 2 root root 4096 2005-11-16 10:24 logs
drwx------ 9 root root 4096 2005-11-05 00:28 Maildir

Danny Regan

# touch /etc/skel/logs/procmaillog
# and of course make the same in the existing accounts using owners perms

Good documentation and howto's are difficult to find - thank you, you might (or not) like to add this to your howto.

As a newbie, I would have liked a bit more on procmail - I still am having difficulty working it out - recepies<guh>.


[ Parent ]

IMAP server with dovecot - Passwords?
Posted by simms (216.46.xx.xx) on Thu 22 Dec 2005 at 14:13
hey guys,

the tutorial is great -- worked like a charm.
however, what i'd like to know now is how to make it so that when i log into dovecot via IMAP using my real username, i can use a different password than the 'real' one which is associated with my system account (i.e. from /etc/passwd).

any ideas?

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by Anonymous (68.107.xx.xx) on Mon 1 May 2006 at 23:27
One thing I hate about Dovecot is that it expects maildir folders to be hidden files.

I think that sucks, badly.

I often script email processing, and it is much easier if the folders are not hidden.

Any way to change this?

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by mzilikazi (75.70.xx.xx) on Thu 28 Dec 2006 at 05:09
[ View Weblogs ]
Apparently dovecot.conf has changed somewhat since this howto was written. You can no longer specify imap_listen or else you get:

dovecotError: Error in configuration file /etc/dovecot/dovecot.conf line 28: Unknown setting: imap_listen

So I just left that out and it seems to work.

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by Anonymous (83.160.xx.xx) on Sun 31 Dec 2006 at 15:31
Also in etch the config file has changed. So don't use default_mail_env but mail_location:
# Location for users' mailboxes. This is the same as the old default_mail_env
# setting. The default is empty, which means that Dovecot tries to find the
# mailboxes automatically. This won't work if the user doesn't have any mail
# yet, so you should explicitly tell Dovecot the full location.

[ Parent ]

Evolution Client Question
Posted by rboyes (203.113.xx.xx) on Tue 27 Mar 2007 at 06:10
My current setup is Debian Etch with Exim4 set to mbox format. Users currently use Evolution to read and store email. I would like to change Exim to maildir format and use imap to allow users to read mail remotely. What concerns me is whether the emails that users currently have stored in their /home/<user>/.evolution directory can be "imported" onto the imap server (i.e. be visible from a remote client)?

I've come across howtos that describe converting evolution's storage to maildir but this version of evo (2.6.3) doesn't appear to have that functionality.

Regards,

Ryan

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by kroshka (66.252.xx.xx) on Wed 25 Apr 2007 at 19:52
[ View Weblogs ]
Why not us uw-imapd, it actually has no configuration file and just works right away out of the box. Just to quote part of its documentation:

http://www.washington.edu/imap/documentation/formats.txt.html

"Soapbox on File/Message Formats

If it sounds from the above descriptions that we're not putting
too much effort into file/message formats, you are correct.

There's a general reason why file/message formats are a bad idea.
Just about every filesystem in existance serializes file creation and
deletions because these manipulate the free space map. This turns out
to be an enormous problem when you start creating/deleting more than a
few messages per second; you spend all your time thrashing in the
filesystem.

It is also extremely slow to do a text search through a
file/message format mailbox. All of those open()s and close()s really
add up to major filesystem thrashing.


What about Cyrus and Maildir?

Both formats are vulnerable to the filesystem thrashing outlined
above."

That to me is a very legitimate reason to not use a file/message or maildir type format. Converting mailbox formats for uw-imapd is also very easy (man mailutil). I just succesfully did that, converting from "unix" format to "mbox" to permit shared access.

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by kroshka (66.252.xx.xx) on Wed 25 Apr 2007 at 19:54
[ View Weblogs ]
mbox should be mbx

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by kroshka (66.252.xx.xx) on Wed 25 Apr 2007 at 20:09
[ View Weblogs ]
Just for informational purposes and not to add to a holy war, another quote:

"6.9 Why don't you support the maildir format?

It is technically difficult to support maildir in IMAP while maintaining acceptable performance, robustness, following the requirements of the IMAP protocol specification, and following the requirements of maildir.

No one has succeeded in accomplishing all four together. The various maildir drivers offered as patches all have these problems. The problem is exacerbated because this implementation supports multiple formats; consequently this implementation can't make any performance shortcuts by assuming that all the world is maildir.

We can't do a better job than the maildir fan community has done with their maildir drivers. Similarly, if the maildir fan community provides the maildir driver, they take on the responsibility for answering maildir-specific support questions. This is as it should be, and that is why maildir support is left to the maildir fan community."

Here uw-imapd is being used for about 50 or so users (more if you count various test and external accounts) and it works well.

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by Anonymous (61.95.xx.xx) on Fri 28 Dec 2007 at 09:39
thank u

[ Parent ]

Re: Setting up an IMAP server with dovecot
Posted by Anonymous (92.52.xx.xx) on Wed 1 Apr 2015 at 07:29
As of holy war (maildir vs mailbox), please google for "Benchmarking mbox versus maildir" on the Courier webpage. Both systems have some advantages, however Maildir is often faster.

We've been using the mailbox with Courier IMAP server for 10 years and we just don't see performance problems with 460+ users. We consider Mailbox as advantage when need to script or debug.

[ Parent ]

Re: My Mail doesn't receive anything
Posted by Anonymous (125.160.xx.xx) on Thu 17 Jul 2008 at 08:43
Hello, Thank you. I've followed the instruction. And goes perfect. I use postfix, dovecot, and mysql. But when i use squirrelmail to sent to my mail. i don't receive anything. When i looked at mail.log => inbox= ... is blank

[ Parent ]