Electronic mail or e-mail is an important part of your professional business communication. For your personal use or if you are a home – business, a free web-based email service may be enough, but if you are running a large business, like an e-commerce site, then a dedicated mail server will be required.

There are numerous benefits when you configure SMTP server in Linux server. Here are some of the benefits you get with a Linux mail server:

  • Extremely fast, reliable, secure and scalable.
  • Does not require expensive hardware.
  • Supports POP3, IMAP and web mail access.

You can install a powerful anti-spam filter and an effective anti-virus to make it more secure.

There are various ways to configure the server and run it according to your requirements. But I find Postfix to be one of the coolest open source mail transfer agents (MTA) to set up and most trustworthy too.

It can be deployed in single-user environment and multiple users’ environment with equal ease. It works marvelously well everywhere.

And in this article, I am going to show you how to set Postfix server on Linux environment.

NOTE: For the purpose of this article, we will be installing Postfix on CentOS Server (the release is 7) and the domain used is www.znettest.tk. You will need to substitute your particular domain (which must be a FQDN).

Step by step guide to install a mail server in CentOS 7

Before starting, update the system and install epel release in your server.

# yum update – y.

# yum install epel-release – y

Installation

Postfix mail server can be simply installed by following these steps:

1) Install postfix packages by typing the command:

# yum install postfix – y

That’s it! The installation will spontaneously start the Postfix daemon for you. As soon as the installation is complete, you can try it out to make sure that you can link to your Postfix server with the command:

# telnet localhost 25

It will produce something on the screen like:

Trying ::1…
Connected to localhost.
Escape character is ‘^]’.
220-mail.znettest.tk ESMTP Exim 4.89_1 #1 Tue, 20 Feb 2018 13:29:17 +0530
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.

Note: Here, mail.znettest.tk is the hostname of this server.

Configuring SMTP server in Linux

Configuring Postfix

The Postfix mail server has one important configuration file /etc/postfix/main.cf where all the details are stored for the mail service.

Open the file in the vi or any other text editor and look for the following section:

# vi /etc/postfix/main.cf

Myhostname=
inet_interfaces= all
inet_protocols= ipv4
alias_maps = hash: /etc/aliases
mydestination =
mynetworks =

These are the sections of the configuration file you must emphasize on. And, I must say, there isn’t much to do. Underneath are the sections you need to configure:

myhostname: This parameter specifies the internet hostname of this mail daemon. The default is to use the fully-qualified domain name.

mydestination: This parameter specifies which destinations this machine will deliver locally. Use the configuration locally which has been provided by default in the server and change the localhost to the domain name.

mynetworks: This line is a bit riskier. This entry will define authorized destinations that mail can be relayed from. If you are thinking to add your subnet here, there are partial chances of its success.

You can go with mynetworks entry that looks like:

mynetworks = 127.0.0.1/8

The above entry is a safe entry and defines local machines only.

The inet_interfaces parameter specifies the network interface addresses on which it receives mails. By default, the software ensures all active interfaces on the machine. The parameter also controls the delivery of the mails to the user@[ip.address].

inet_protocols= ipv4

By default, it is set to IPv4 to ensure faster delivery of mails.

Now, save and exit the vi editor. Then start/enable the mail service with the command so that it will be Active after server reboot.

# systemctl restart postfix

# systemctl enable postfix

Installation of mail service has been completed. Now it is time to create one user and test it.

Creating users

Since this is a Linux mail server, you have to make sure that you have a user name that resembles every email address you need. You can create users with the command:

# useradd -m USERNAME (USERNAME is the real name of the user).

The next step is to give the username, a password with the command:

# passwd USERNAME

Testing Your Server

You can use mail utils package to install necessary things to send the mails by using the command:

Yum install mail x – y

After this, try any mail Id by typing:

Mail (mailid)

It will ask the subject. Enter the content you want to send.

After completing, exit and end the mail by using a dot (.)

Now your mail server is ready to deliver mails as per your needs. 

Also, you can use SMTP relay to allow a multifunction device, printer, or an application for sending e-mails by using Office 365 and Exchange Online. And with ZNetLive, you get different Microsoft Office 365 plans as per your needs so that you can operate your business efficiently from anywhere and anytime.

Feel free to drop your comments in the section below.

Services ZNetLive offer:

Cheap Domain Name

Linux Shared Hosting India

Managed WordPress Hosting India

VPS Hosting India

Dedicated Server India

Umesh Dubey

Umesh, Team Lead - Technical, is a Microsoft products’ expert with enviable certifications like RHCE, MCPS, MCSA and MCSE. An excellent team player, he utilizes his expertise of over 7 years in the technical sphere to handle technical issues brilliantly and dedicatedly value adds to the system administration and management fields. He can be seen drawing or playing chess in free time.
Umesh Dubey