24/7/365 Support

Enabling IMAP and POP3 with Dovecot in Ubuntu

In this recipe, we will learn how to install and set up Dovecot to enable accessing e-mails over IMAP and POP3 protocols. This will enable mail clients such as thunderbird to download e-mails on a user's local system.

Getting ready

You will need access to a root account or an account with sudo privileges

Make sure that you have set up Postfix and are able to send and receive e-mails on your server.

You may need an e-mail client to connect to and test the Dovecot setup.

How to do it…

Follow these steps to enable IMAP and POP3 with Dovecot:

First, install the Dovecot binaries from the Ubuntu main repository:

$ sudo apt-get update

$ sudo apt-get install dovecot-imapd dovecot-pop3d

You will be prompted for a hostname to be used for certificate generation. Type in a full hostname, for example mail.example.com. You can skip this step if you already have certificates.

Next, proceed with configuring Dovecot. Open the file /etc/dovecot/dovecot.conf:

$ sudo nano /etc/dovecot/dovecot.conf

Find the Enable installed protocols section and add a new line to set the protocols that you want Dovecot to support:

protocols = pop3 pop3s imap imaps

Open /etc/dovecot/conf.d/10-mail.conf and set the mailbox to be used. Dovecot supports mbox as well as Maildir. Make sure you set the correct path of your mail directory:

mail_location = mbox:~/mail:INBOX=/var/spool/mail/%u

Open /etc/dovecot/conf.d/10-ssl.conf and uncomment or change the following lines to enable SSL authentication. Here, I have used certificates created by Postfix. You can use your own certificates or use the one generated by Dovecot:

ssl = yes

ssl_cert = < /etc/ssl/certs/ssl-cert-snakeoil.pem

ssl_key =</etc/ssl/private/ssl-cert-snakeoil.key

Restart the Dovecot daemon:

$ sudo service dovecot restart

Test Dovecot by creating a telnet connection. You should see an output similar to the following:

$ telnet localhost pop3

How it works…

Dovecot is one of the most popular Mail Delivery Agents (MDA) with support for IMAP and POP3 protocols. It works with both major mailbox formats, namely mbox and Maildir. The installation process is simple, and a minimal configuration can get you started with your own IMAP or POP3 service.

Dovecot developers have tried to simplify the configuration by separating it across various small files for each section. All these configuration files are located under /etc/dovecot/conf.d. If you prefer to use a single configuration file, you can replace the default file with the entire working configuration. To get all enabled configurations, use the doveconf -n command:

# mv /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf.old

# doveconf -n > /etc/dovecot/dovecot.conf

In this recipe, we have configured Dovecot to support POP3, POP3 secure, IMAP, and IMAP secure. You can choose a single protocol or any combination of them. After setting protocol support, we have set the mailbox type to mbox. If you are using Maildir as your mailbox format, instead replace the mailbox setting with following line:

mail_location = maildir:~/Maildir

Now, when a user wants to check his e-mails, they need to authenticate with the Dovecot server. At this stage, only users with a user account on the server will be able to access their e-mails with Dovecot. To support users without creating a user account, we will need to set up Virtual Users, which is covered in the next recipes.

If you plan to skip SSL setup, you may need to enable plain text authentication under the configuration file, /etc/dovecot/conf.d/10-auth.conf. Find and uncomment the following line and set it to no:

disable_plaintext_auth = yes

The default setting is to allow plain text authentication over SSL connections only. That means the clients that do not support SSL will not be allowed to log in.

See also

Dovecot wiki Quick-configuration at http://wiki2.dovecot.org/QuickConfiguration

Help Category:

What Our Clients Say