Dovecot on RHEL/CentOS based distributions

If you have installed the Postfix mail server to
operate as the Simple Mail Transfer Protocol (SMTP) service on an
email server, you might still need a way to retrieve the incoming mail
from the server.

This article shows you how to install and configure Dovecot, an
open-source Internet Message Access Protocol (IMAP) and Post Office Protocol
version 3 (POP3) server application designed specifically for Linux® and
UNIX® operating systems. Dovecot retrieves emails from Postfix and
delivers them to the relevant mailbox on the server.

You can get your mail through Dovecot by using either the POP3 or the IMAP
protocol.

Prerequisites

You need the following operating system and software to use Dovecot:

  • A CentOS® 7.0 or later Linux distribution
  • Postfix

Install Dovecot

Download and install the Dovecot package by running the following command:

NOTE: For CentOS 8 The only difference is that 8 versions (RHEL 8 / Alma Linux 8 / Rocky Linux 8) is that this versions uses dnf instead of yum.

For instalation process, use the following command:

It is the only difference, the exact same process it's necesarry after execute this command

Configure Dovecot

Once the installation finished, you need to configure the services in the
configuration file at /etc/dovecot/dovecot.conf. This example uses
the vi text editor, but you can use any text editor that you want.

1- Use the following command to open the file in vi:

2- Uncomment the following lines in the file and, if necessary, change them to
reflect your plans for the environment:

Configure the location of the Mailbox

Next you need to configure the location of the Mailbox file,

1- Use the following command to open the file in vi:

2- Uncomment the following line in the file and, if necessary, change them to
reflect your plans for your environment:

Configure Postfix SMTP authentication

You can set the location for your mail by editing the configuration file at
/etc/dovecot/conf.d/10-master.conf.

1- Use the following command to open the file in vi:

2- Either add or uncomment the following line in the configuration file:

Configure POP3

Finally, configure the /etc/dovecot/conf.d/20-pop3.conf file, which enables
older and less popular email clients to connect and transmit messages
correctly.

1- Use the following command to open this file in nano:

2- Uncomment or add the following lines:

Create a mailbox

The example in this section adds a mailbox that a hypothetical user named Joe
Bloggs (joe.bloggs) can use to send and receive emails.

You can create a user for this example, or you can use an existing user.

1- If necessary, use the following command to make a new user:

2- Use the following command to create the mail directory for your user:

3- Give ownership of the mailbox that you just created to joe.bloggs by
changing its permissions:

Start Dovecot

Use the following steps to start the Dovecot service:

1- Use the following chkconfig command to verify that the Dovecot
application will run when the server is restarted:

2- Use the following command to start the Dovecot service:

Configure Postfix

Next, you need to configure Postfix to enable your email client to connect to
your new SMTP server.

1- Use the following command to open the file at /etc/postfix/main.cf in
vi:

2- Add the following lines to the file:

3- After you have added the preceding lines, exit the main.cf file and
restart the Postfix service by using the following command:

Add ports to iptables

Now that you have enabled secure SMTP Secure Sockets Layer (SSL), you should
allow connections to port 587 by opening the port for your server in iptables.

1- Add the rule for this port by entering the following command:

2- Add the POP and IMAP ports, as well as their secure counterparts:

3- Use the following commands to save the iptables rules and restart iptables:

Use the Feedback tab to make any comments or ask questions. You can also start a conversation with us.