building a messaging server part three
Configuring Dovecot
With Postfix setup and able to send and deliver mail, we can configure Dovecot to retrieve the mail for the end user.
Installing Dovecot
To install Dovecot, simply run:
apt-get install dovecot-imapd dovecot-pop3d
Configuring Dovecot
The Dovecot configuration file (/etc/dovecot/dovecot.conf) is incredibly detailed. You really have to respect the developers for commenting the file so well -- there's almost no need to check into the documentation.
There are also numerous options available in the config file. Fortunately, this project won't nearly use all of them.
To get simple IMAP and POP3 access up and running simply
configure the file like this (without line numbers):
1. protocols = imap pop3
2. disable_plaintext_auth = no
3. default_mail_env = maildir:/var/spool/vmail/%d/%n/
4. protocol pop3 {
5. pop3_uidl_format = %08Xu%08Xv
6. }
7. auth default {
8. mechanisms = plain login
9. passdb passwd-file {
10. args = /etc/postfix/virtual/passwd
11. }
12. userdb static {
13. args = uid=1001 gid=1001 home=/var/spool/vmail/%d/%n/
14. }
15. user = vmail
16. }
Line one specifies what protocols Dovecot will support. If you don't want POP3, for example, then leave it out.
Line two enables plaintext authentication -- what all email clients support by default.
Line three sets the default mail environment to the location of the email address in question. the %d and %n are varaibles specific to Dovecot. In this case, %d is for the domain portion of the email (server1.local) and the %n is for the name (joe). There are more variables listed in the config file comments.
Lines four through six specify any configuration options for POP3. In this case, it's the UIDL setting -- which deals with mail clients that leave their mail on the server. The value is set to the recommended choice in the configuration file.
Line seven starts the auth block. The mechanisms that will be supported are plain and login.
The passwd-file sets the location of the password file for the virtual users. This file is needed
since the users aren't real system users, their credentials need to be stored somewhere.
The userdb section defines a static user to access the mailboxes. The vmail user was created for Postfix to deliver the mail, so the same user will just be used to retrieve it.Please note that you could set Dovecot up to use a different user for each mailbox or groups of mailboxes if you'd like.
Finally, the last line specifies who will have read access to the passwd file. vmail will be used again.
Creating the password file
The last step is to create the actual password file. The format of the file will look like this:
account:password
Two fields are the minimum amount for a working password file. Dovecot supports more fields that can be used with various plugins and options.
Similar to the owner field used with the Postfix vdomains.txt file, a third field will be added to the password file.
account:password:owner
To create the actual hashed password, Dovecot now comes with a utility called dovecotpw. dovecotpw supports a variety of different password hashes -- HMAC-MD5 is the default:
dovecotpw -p MyPassword!
{HMAC-MD5}de025947028f81cbf4e5a68a02ff5be6dce90ca3d8287e7c4bb333babd1ee0b7
So the full entry in the password file will be:
joe@server1.local:{HMAC-MD5}de025947028f81cbf4e5a68a02ff5be6dce90ca3d8287e7c4bb333babd1ee0b7:joe
If you're upgrading from an old password file that might be using MD5-crypt, they will still work with the new version of Dovecot. You can even use different password hashes for each user:
joe@server1.local:{HMAC-MD5}de025947028f81cbf4e5a68a02ff5be6dce90ca3d8287e7c4bb333babd1ee0b7:joe
tom@server1.local:$1$b9HNLtjE$WbBFJtBmLsvGu7TA9ckD11:tom
Testing
After all this is set up, start the dovecot server. If you receive no error messages in either the command prompt or log files, test it out:
telnet mail.server1.local 110
user joe@server1.local
pass MyPassword!
If you receive an OK reply, Dovecot is working fine.
