官术网_书友最值得收藏!

Enabling IMAP and POP3 with Dovecot

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:

  1. First, install the Dovecot binaries from the Ubuntu main repository:
    $ sudo apt-get update
    $ sudo apt-get install dovecot-imapd dovecot-pop3d
    
  2. 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.
  3. Next, proceed with configuring Dovecot. Open the file /etc/dovecot/dovecot.conf:
    $ sudo nano /etc/dovecot/dovecot.conf
    
  4. 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
  5. 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
  6. 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
  7. Restart the Dovecot daemon:
    $ sudo service dovecot restart
    
  8. 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

主站蜘蛛池模板: 望都县| 舒兰市| 盐边县| 贡觉县| 建阳市| 广汉市| 天峻县| 淳安县| 长泰县| 洪湖市| 邢台县| 合川市| 巴青县| 察哈| 莫力| 濉溪县| 简阳市| 城步| 玉门市| 新巴尔虎右旗| 区。| 莎车县| 新和县| 金沙县| 高邑县| 喀什市| 朝阳区| 邯郸市| 营山县| 澄城县| 宁南县| 英山县| 和静县| 柘荣县| 保康县| 龙海市| 屏南县| 兰州市| 十堰市| 安福县| 吉隆县|