What is Dovecot?
Let's follow the path of a typical mail message from start to finish and see where Dovecot would fit.
To begin with, someone out in the world creates a mail message using their e-mail program. In general, a program which allows someone to send and receive e-mail is known as a Mail User Agent or MUA. Examples of typical MUAs include Mozilla Thunderbird and Microsoft Outlook Express. Whatever MUA was used, a message was created and sent to that user's mail server. The mail server does not interact with people directly like the MUA does; rather, its job is to receive e-mail from another computer and either send it on to wherever it needs to go, or handle final delivery of e-mail. The "mail server" is known as a Mail Transfer Agent or MTA. The MTA then checks the message to determine the recipient, and queries the Domain Name System (DNS) servers to find out which other MTA is responsible for handling e-mail for the recipient in question. It then sends the message to that MTA. At this point, the message has traveled from the remote user's computer to their mail server, and has reached the mail server which handles e-mail for the recipient in question. Now what happens?
Depending on the network configuration, it's quite possible that the message will be relayed to yet another MTA. But at some point, one MTA will take responsibility for the message and become responsible for delivery. At this time, the MTA will pass the message to a Mail Delivery Agent (MDA). At its core, an MDA is responsible for actually storing the message to disk. Some MDAs do other things as well, such as filtering mail or delivering to subfolders. But it is the MDA that stores the mail on the server.
Now, it's time to check your mail. You start up your MUA, and it queries your mail server using one of the standard protocols: IMAP or POP3. The mail server confirms your identity, then retrieves the list of messages from the mail storage area and returns them to the MUA. Your MUA then presents those message to you, and you can now read your mail.
So where does Dovecot fit into this?
As an IMAP and POP3 server, Dovecot provides a way for Mail User Agents (MUAs) to access their mail. So when a user's MUA contacts the mail server, the software which answers that request is an IMAP or POP3 server. IMAP and POP3 servers take requests from MUAs and answer those requests by accessing e-mail messages stored on the server and feeding them out to the MUA using IMAP or POP3. Dovecot is one program which can provide that IMAP and POP3 server functionality.
In addition, Dovecot provides functionality for final message delivery with the Dovecot LDA (Local Delivery Agent). The LDA is responsible for storing e-mail messages into the message store. Local delivery can be carried out by the MTA itself, or by a separate Mail Delivery Agent, or using the Dovecot LDA. The choice is made according to the requirements of the particular server installation.
Note that Dovecot is NOT responsible for receiving mail from other servers. Dovecot only handles e-mail (a) messages coming out of the local message store, going out to IMAP and POP3 clients, and (b) messages which have already been received by the MTA and are to be stored into the local message store.
IMAP and POP3 are the two common protocols used by MUAs to communicate with mail storage servers. POP3 is commonly used by users who do not have a high-speed connection to the mail server. One of POP3's basic principles is that MUAs download mail and store it locally (on the user's computer) - and then delete the mail from the server. IMAP is intended for LANs and high-speed connections. The intent of IMAP is to contact the server each time a given message needs to be read (apart from MUA-specific caching). Dovecot has a number of optimizations for IMAP that make it an exceptionally good performer for most IMAP scenarios.
Dovecot is not involved with actual reception of e-mail. That functionality is provided by an MTA such as Exim or Postfix. Once e-mail has been received into the MTA, then it can either be delivered directly by the MTA, or by another MDA, or it can be passed to the Dovecot LDA for final delivery. The choice depends on various factors specific to the installation.
There are two primary storage options of mail in the *NIX world: mbox and Maildir. mbox stores multiple messages - sometimes hundreds or thousands of messages - in a single file. Maildir stores each message as a separate file. Both mbox and Maildir have wide support across various e-mail software including MTAs and MDAs, and both are fully supported by Dovecot. Dovecot also offers its own high-performance mailbox format: dbox.
Dovecot configuration primarily consists of mail storage type, mail storage location, user list, and password list.
Dovecot currently supports a variety of user & password sources, including *NIX passwd, shadow, PAM, LDAP, SQL, and vpopmail. It's usually best to select a source supported by all the parts of your overall mail solution, including your MTA, MDA, and Dovecot.
Dovecot works best when e-mail is delivered using the Dovecot LDA which, if used, needs to be "plugged in" to the MTA so that the MTA "knows" how to correctly pass messages to the Dovecot LDA. When using Dovecot's own dbox mail storage formats (sdbox/mdbox), the Dovecot LDA must be used as only Dovecot can access those formats.
Optionally, an existing delivery configuration can be used without using the Dovecot LDA, using Dovecot purely as an IMAP and/or POP3 server. However in such cases care needs to be taken to ensure that the MDA and Dovecot cooperate properly (for example, when using mbox it is crucial that a compatible mbox-locking strategy is used to avoid corruption of mbox files).