Mail Server Install & Setup in CentOS 7

Mail Server

A mail server is the computerized equivalent of your friendly neighborhood mailman. Every email that is sent passes through a series of mail servers along its way to its intended recipient. Although it may seem like a message is sent instantly – zipping from one PC to another in the blink of an eye – the reality is that a complex series of transfers takes place. Without this series of mail servers, you would only be able to send emails to people whose email address domains matched your own – i.e., you could only send messages from one example.com account to another example.com account.

The basic terms that we will use in a mail server are:

POP3: POP (Post Office Protocol – Post Office Protocol) is the protocol that allows the message to be received and this protocol does not require a permanent connection to the internet for its operation.

IMAP: IMAP (Internet Message Access Protocol) is a protocol that allows the email client to connect to the email account and display the stored email messages.

SMTP: SMTP (Simple Mail Transfer Protocol) is a text-based protocol that is used to exchange mail messages between different devices.

MTA: MTA (Mail Transfer Agent) is a server whose function is to transfer emails and their management on the Internet. Some known MTAs are Sendmail, Postfix, etc.

POP3DOVECOT: Dovecot is an incoming mail server which supports the protocols mentioned above.

With these concepts in mind, we will proceed to the configuration of our mail server in CentOS 7.

install EPEL repo on a CentOS 7

The following instructions assumes that you are running command as root user on a CentOS 7 system and want to use use Fedora Epel repository.

# Method 1->Install Extra Packages for Enterprise Linux repository configuration (recommended)

Just type the following yum command on a CentOS 7 or RHEL 7:
sudo yum install epel-release

Fig.01: How To Install EPEL Repo on a CentOS and RHEL 7.x

 

# Method 2->Install the extra EPEL repositories from dl.fedoraproject.org

The command is as follows to download epel release for CentOS and RHEL 7.x using wget command:

cd /tmp
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
ls *.rpm

To install epel-release-7-5.noarch.rpm, type:
sudo yum install epel-release-latest-7.noarch.rpm
Sample outputs:

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.vbctv.in
 * extras: mirror.vbctv.in
 * updates: mirror.vbctv.in
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
================================================================================
 Package                Arch             Version         Repository        Size
================================================================================
Installing:
 epel-release           noarch           7-11            extras            15 k
 
Transaction Summary
================================================================================
Install  1 Package
 
Total download size: 15 k
Installed size: 24 k
Is this ok [y/d/N]: y
Downloading packages:
epel-release-7-11.noarch.rpm                               |  15 kB   00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : epel-release-7-11.noarch                                     1/1 
  Verifying  : epel-release-7-11.noarch                                     1/1 
 
Installed:
  epel-release.noarch 0:7-11                                                    
 
Complete!

Install Apache for Mail Server Management

The next step is to install Apache using the parameter –disablerepo=epel* which allows us to perform the installation directly from the official repositories. We will use the following command.

sudo yum -y install --disablerepo=epel*

Install Necessary Apps

Once the previous process is done, we will install the following applications:

  • Sendmail (Which will be used to send emails)
  • Dovecot
  • Squirrelmail (It will be our email web client)

For this, we will use the following command

sudo yum -y install sendmail sendmail-cf dovecot squirrelmail

Now we will validate the Postfix service. This default service is installed in CentOS 7, we proceed to look for it, and in case of finding it we continue to stop it, for this we will use the following commands.

rpm -qa | grep postfix

systemctl stop postfix

Next, we will modify the name by a valid domain name, in this case, we will use the name thelinuxcode.com and enter the following in CentOS 7:

sudo hostname thelinuxcode.com

Dovecot Configuration

To configure the Dovecot parameters, we must enter the following path /etc/docott/docott.conf, we can use the preferred editor, in this case, we will use nano.

sudo nano /etc/dovecot/dovecot.conf

We will see that the following:

In this configuration, we must locate the following line

Protocols we want to be serving

There we uncomment the line Protocols=imap pop3 lmtp (Removing the symbol #) and leave the protocols that we will use, in this case, IMAP and pop3.

We save the changes using the key combination: Ctrl +O

And we left the editor using the combination: Ctrl +X

Now we will enter the path /etc/dovecot/conf.d/10-mail.conf for editing, enter:

sudo nano /etc/dovecot/conf.d/10-mail.conf

There we must copy the line mail_location = mbox: ~/mail:INBOX=/var/mail/%u and paste it in the mail_location field under the line <doc/wiki/MailLocation.txt> and taking into account remove the symbol #.

Finally, we access the file located in the path /etc/dovecot/conf.d/10-auth.conf, we will enter:

sudo nano /etc/dovecot/conf.d/10-auth.conf

There we have to uncomment (remove symbol #) from the line

disable_plaintext_auth = yes

We save the changes using the key combination: Ctrl +O

And we left the editor using the combination: Ctrl +X

Sendmail Configuration

Now we must access the following path / etc / mail / sendmail.mc to make the changes in the Sendmail configuration; we will use nano to access the edition.

sudo nano /etc/mail/sendmail.mc

There we will locate the line

DAEMON_OPTIONS (“port=smtp,Addr=127.0.0.1, Name=MTA”)dn1

In this line we remove the section associated with Addr, thus leaving the line.

We keep the changes. Once this change is executed we will use the m4 command to modify the Sendmail format from .mc to .cf (It is a compilation), for this we will use the following command.

sudo m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

SquirrelMail Configuration

The next step is to access the path /etc/mail/local-host-names using nano to make some adjustments; we will enter.

sudo nano /etc/mail/local-host-names

There we will enter the name of the domain , in this case thelinuxcode.com

We save the changes. Next we will access using nano to the following route:

/etc/mail/Access

There we must add a line with the name of our domain. We keep the changes using: Ctrl +O

Once these changes are made, we proceed to restart the services using the following commands:

systemctl start httpd

systemctl start sendmail.service

systemctl start dovecot.service

Access Web Console

For this tutorial, we have created two users using the useradd command called correosolvetic and solvetic1.

Next, we must go to a browser and enter the following syntax:

http://IP_address/webmail

In our case, we enter

http://192.168.0.11/webmail

We enter our credentials and we will see the following error.

This error is due to the fact that the folder that will contain the mail server information doesn’t exist.

To solve this we must use the following command to create the respective folder in the root of the selected user, in this case mailcode (and apply it to each of the created users)

touch /home/correosolvetic/mail/.imap/INBOX

Then we must modify the owner of the folder using the following commands:

sudo chown -R mailcode:mailcode /var/www/html/mailcode

Now again we try to access and we will see the following.

Using this method we can configure a mail server on our Linux systems, in this case, CentOS 7 to allow intercommunication between the various users of the organization practically and straightforwardly.