How to Install and configure mail-server (Postfix, Dovecot, MariaDB/MySQL) in CentOS/RHEL 7

It is assumed that you have already installed and configured Apache, PHP/MySQL and MariaDB. Instructions for setting up can be read at this link.


Installing PostfixAdmin

Download archive with PostfixAdmin, unpack and let its contents in different folders:

Now let’s create the MySQL database which will store information on postal users:

Let’s agree that here and below instead of %VMailDB% and %VMailUser% and %VMailPassWord% to enter the database name, user name, and password. No percent sign!

Write the data to the created database in the configuration file and make a few extra PostfixAdmin settings:

Connect PostfixAdmin to Apache Web server:

Open the link in your browser
Check whether written anytime OK in requirements. Next, set the password to change settings and save to the file hash of the resulting /etc/postfixadmin/config.local.php

Now open the browser again link, enter a password and create the Admin account.

The administrator account has been created, open the PostfixAdmin at and enter the administrators data. Our goal is to create a domain and user mailboxes.
To create a domain, choose «Domain List» and click «New Domain». Fill in the form (in the «Transport» you should choose «dovecot») and click on the «Add Domain» button.
After you create a domain-create users and aliases. To do this, choose «Virtual List» and click «Add Mailbox». Fill in the form and click on the button «Add Mailbox». The default domain is created, a number of system aliases, mail with which eventually redirect to the address You must now create a redirect with the name to e-mail the administrator. To do this, choose «Virtual List» and click «Add Alias». Enter admin in the Alias field, in the «To» box, enter the full address to redirect, and click on the button «Add Alias».
Now open the list of mailboxes and aliases created by selecting «Virtual List» in menu «Virtual List». If everything is OK, proceed to further configure your mail system.


Fix PostfixAdmin work with Russian symbols

  • Firstly correct character set in MySQL tables:
  • And now the correct php scripts PostfixAdmin to work properly with UTF-8:
    Fix to all calls to the function htmlentities in the directories /usr/share/postfixadmin and /usr/share/postfixadmin/templates, you need to add the two arguments |, ENT_QUOTES, 'UTF-8'|.


Fix bug with saving extra-options for fetchmail

  • In the file fetchmail.php function escape_string runs twice, so slashes are stored in MySQL.


Installing postfix

To determine where they will physically be user mailboxes. If you plan to leave them in the default folder, skip this item. I have the mail physically rests with the special section, which mounted as well in /srv. To do so is Mount section and do the following:

In CentOS 7 the default mailer is a postfix, in previous CentOS versions you had to run the command:

Edit the main configuration file postfix:

«VIRTUAL DOMAINS» unit is responsible for our accepted domains and users that we tended to PostfixAdmin. Unit «SASL» need to authenticate users on the Simple Mail Transfer Protocol (SMTP) to send mail through our servers. In the «TRANSPORT LAYER SECURITY» set our SSL certificates so that all communication with the mail server in encrypted form. A block of «RESTRICTIONS» SMTPD need to trim away the lion’s share of spam.

Create a list of exceptions to the RBL list. In order to be able to receive mail from those servers even if they somehow get into RBL list.

Create a list of hosts that can without authorization to send mail via our mail service (a very dangerous thing, to my memory really is needed for only one blade center who couldn’t log in, everything else is authenticated on the smtp quietly and no problems sending mail).

Configure the dovecot as mail transport:

Create extra configuration files with data for connection to SQL tables with data on our domains and users:

Postfix is configured, but it will not run until you configure the dovecot.


Installing dovecot

Install dovecot server and associated plugins to work with database MySQL and Sieve filters:


Starting services

Run the dovecot and postfix and add them to the startup:


Checking SMTP service

Now let’s check whether postfix accept mail for our domain:

Thus check the TLS connection and authorization:


Configuring the firewall

Checking that postfix is functioning and ready to accept mail and open it to the world:


Configuration of FetchMail

First of all install the needed packages:

Now let’s create the config file for fetchmail:

Then we will prepare a script that will be run by cron at certain times and pick up for us mail:

Add this script in cron:

Now we need to login to our PostfixAdmin and configure email accounts, from which mail will be collected. To do this, open the Web interface PostfixAdmin and menu, then choose the «Fetch Email» click «New Entry». Select the Mailbox where you want to be mail, enter the remote server name, user name, and password, just choose the Protocol that will be picked up mail (IMAP/POP3). If the IMAP server with multiple folders for each folder you will need to create a separate entry for mail collection, and in each entry in the field «Folder» to indicate its location. If the mail is collected using Secure Sockets Layer (SSL) encryption, you must tick the «SSL active», just as it is desirable to complete the «SSL fingerpring (md5)» to Fetchmail is used for Secure Sockets Layer (SSL) certificate. Then, save the record by clicking on the «Save Changes».
And to get the fingerprint you need to run the following command:

In this article you can read about configuring spam filter DSpam. There is a sample file with Sieve rules. And in this article you can read about the installation and customization of the Web interface for mail – RoundCube.


  1. realmadrider
    11.03.2015 - 12:51

    I have mistakenly deleted mail user and group. I’ve tried to recreate them, but seems like something’s wrong as I get lots of “access denied” and “Relay access denied” in my logs. Another point is that the line “bad uid 8 in virtual_uid_maps” shows up a lot in logs even though the “mail” user obviously has the uid 8. What am I doing wrong?

  2. Hi,
    please write manual to enable quota with dovecot & mysql.

Leave a Reply