Picking up where we left off a while ago, let's add yet another feature to our Ubuntu server. We've already looked at using Postfix with multiple topics (see Postfix on Ghacks). But we never discussed a means to deliver the mail from the server to the client. That will now change. Linux has multiple ways to deliver email to clients. One of the easiest (as well as most flexible) means is via Dovecot.
Dovecot is an open source IMAP/POP server that runs on either Linux or UNIX systems. Dovecot is suitable for both small and large installations (I just recently installed Dovecot on a 300+ user system) and will work in the background like a workhorse.
In this article I will show you how to install Dovecot and get it up and running with either IMAP or POP quickly and with as little pain as possible.
Since we are installing on a Ubuntu machine, installing Dovecot is as simple as running the command sudo apt-get install dovecot-common dovecot-imapd dovecot-pop3d. You can actually install either dovecot-imapd or dovecot-pop3d depending upon which protocol you need to support.
Once installed the executable command is /etc/init.d/dovecot start.
There is only one configuration file you need to deal with. That file will be located in either /etc/dovecot.conf or /etc/dovecot/dovecot.conf. Believe it or not, the default configuration file is fairly well set up for you. You will only have to make a few modifications. So don't let the 1,000+ line configuration file look you in the eye and defeat you. You can best this beast with little time.
The first configuration you will need to make is to configure the protocol. Look for the line:
protocols = pop3 pop3s imap imaps
You can just leave this as is, or, if you know you are only using certain protocols, edit to suit your set up. Just remove the protocols you do not need.
The next line you need to look for is:
There are two popular choices here:
mail_location = maildir:~/Maildir # (for maildir)
mail_location = mbox:~/mail:INBOX=/var/spool/mail/%u # (for mbox)
In other words, if your users' mailboxes will reside in the home directory, use the former. If the users' mailboxes will reside in /var/spool/mail, use the latter.
Restart and test
Now restart Dovecot with the command /etc/init.d/dovecot restart and let's give this system a test. We'll test this with the help of telnet. Issue the command telent ADDRESS PROTO Where ADDRESS is the address of the server and PROTO is the protocol you want to use (either pop3 or imap). Here's what the test will look like:
telnet localhost pop3
+OK dovecot ready.
+OK Logged in.
+OK 1 messages:
Where USER is a legitimate user on the system and PASSWORD is the password for that user.
If you see the +OK at the end, Dovecot is ready to go. If you have any problems, the best place to look is in /var/log/maillog. And the best way to run that check is by using two terminal windows. In terminal A issue the command tail -f /var/log/maillog and in terminal B run the Dovecot test above. Terminal A should report any issues which will be your starting point for troubleshooting.
Dovecot really is that easy to install. Of course Dovecot is much more flexible than that. In later articles we will discuss other configuration options for this outstanding server.
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.