1. Home
  2. Linux
  3. CentOS
  4. How to Install and Setup a Mailserver on a CentOS 7 VPS with Exim

How to Install and Setup a Mailserver on a CentOS 7 VPS with Exim

How to Install and Setup a Mailserver on a CentOS 7 VPS with Exim
How to Install and Setup a Mailserver on a CentOS 7 VPS with Exim

In the following tutorial, we will teach you how to install and set up a mailserver using Exim and Dovecot on a CentOS 7 VPS.
We will use a CentOS based VPS host plan for this tutorial; it will be pre-installed with minimal CentOS 7 OS.

What is Exim?

Exim is a mail transfer agent (MTA) which is commonly used on Unix-like operating systems. Exim is a free software, which is distributed under the terms of the GNU (General Public License), and it’s trying to be a general and flexible mailer with extensive facilities for verifying any incoming e-mail.

What is Dovecot?

Dovecot is an open-source IMAP and POP3 email server for Linux/UNIX-like systems. It was written with security as its top priority. Dovecot is an amazing choice for both small and large installations.


Begin by sshing to your server then start a screen session with the following command:

## screen -U -S exim-dovecot

After you are in the screen session, update your CentOS 7 VPS with yum as follows:

## yum update


With the following command, we can enable the EPEL repository on the CentOS system:

## yum install http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-2.noarch.rpm

If you receive a 404 not found error, use the following link, https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/, then install the latest epel-release rpm package available.
Confirm that EPEL has been enabled on your system using the following command:

## yum repolist

If EPEL is enabled, install some useful tools with this:

## yum install file perl-Mail-SPF.noarch openssl vim


Because we will be using SSL in Dovecot and Exim, we will need to have an SSL certificate. You may create your own self-signed SSL certificate for mail.mydomain.com with the commands below:

## mkdir /root/SSL/mail.mydomain.com -p
## cd /root/SSL/mail.mydomain.com
## openssl req -nodes -x509 -newkey rsa:2048 -keyout mail.mydomain.com.key -out mail.mydomain.com.crt -days 365

With the command below, we will move the SSL certificate and key to /etc/ssl directory:

## cp mail.mydomain.com.key mail.mydomain.com.crt /etc/ssl/


Use the command below to install exim on the CentOS 7 VPS with yum:

## yum install exim

Now, we will open the file /etc/exim/exim.conf using your favorite editor, then configure exim as follows:

## cp /etc/exim/exim.conf{,.orig}
## vim /etc/exim/exim.conf
primary_hostname = mail.mydomain.com
domainlist local_domains = @ : mydomain.com
tls_advertise_hosts = *
tls_certificate = /etc/ssl/mail.mydomain.com.crt
tls_privatekey = /etc/ssl/mail.mydomain.com.key
auth_advertise_hosts = *

Look for the transport section and modify the following:

driver = appendfile
directory = $home/Maildir

Scroll down to the authenticators section and append the next lines:

driver = dovecot
public_name = LOGIN
server_socket = /var/run/dovecot/auth-client
server_set_id = $auth1
driver = dovecot
public_name = PLAIN
server_socket = /var/run/dovecot/auth-client
server_set_id = $auth1

Initiate the EXIM MTA then append it to the system’s startup using systemctl

## systemctl start exim
## systemctl status exim
## systemctl enable exim



Next, we will install Dovecot on the system using yum:

## yum install dovecot

After it’s installed, configure SSL in Dovecot by modifying the following:

## vim /etc/dovecot/conf.d/10-ssl.conf
ssl = yes
ssl_cert = </etc/ssl/mail.mydomain.com.crt
ssl_key = </etc/ssl/mail.mydomain.com.key

Next we will allow plaintext authentication in /etc/dovecot/conf.d/10-auth.conf:

## vim /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no
auth_mechanisms = plain login

Configure the mailbox location and enter this in /etc/dovecot/conf.d/10-mail.conf:

## vim /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir

Now we’ll set up Dovecot so it grants Exim the ability to use its authentication system in

## vim /etc/dovecot/conf.d/10-master.conf
service auth {
unix_listener auth-client {
mode = 0660
user = exim

Start up Dovecot and append it to the system’s start-up using the following:

## systemctl start dovecot
## systemctl status dovecot
## systemctl enable dovecot

Create a System User:

## useradd -m test
## passwd test


Updated on December 23, 2018

Was this article helpful?

Related Articles

Leave a Comment

[apsl-login-lite login_text='Please login with a social account']