How to Configure SMTP Server in Linux

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.

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.greencloudvps.com 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.greencloudvps.com 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 [email protected][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.