How to setup Simple Mail Transfer Protocol (SMTP) in RHEL 7

How to setup Simple Mail Transfer Protocol (SMTP)

In general, the sender will create the email message and sends to server. Then it will be forwarded to recipient mail server and delivers the mail to client progtram or web mail. The SMTP server service is present in all the servers. In this article we will discuss how to setup Simple Mail Transfer Protocol (SMTP) in RHEL 7.

 

Test environment

Original mail server and central mail server

Original Mail Server: (hostname: mail.linuxhelp.com / IP: 192.168.5.159)

 /etc/hosts file is used for the name resolution.

192.168.5.159 mail.linuxhelp.com mail
::1 mail.linuxhelp.com mail

 

To install Postfix and Firewall

To Install Postfix

[root@linuxhelp ~]# yum install postfix
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
extras 3.4 kB 00:00:00
updates 3.4 kB 00:00:00
updates/7/x86_64/primary_db 3.2 MB 00:00:04

Loading mirror speeds from cached hostfile

* base: centos-hn.viettelidc.com.vn

 Most of linux distribution postfix is default package

 

To Start the service

You can enable it to run on the future reboots

[root@linuxhelp ~]# systemctl start postfix
[root@linuxhelp ~]# systemctl enable postfix

 

To allow mail traffic through the firewall

[root@linuxhelp ~]# firewall-cmd --permanent –add-service=smtp

success

[root@linuxhelp ~]# firewall-cmd –add-service=smtp

success

 

To Configure Postfix
You can configure postfix on mail.linuxhelp.com. The /etc/postfix/main.cf consists of the postfix main configuration file.

 

To Configure Postfix on mail.linuxhelp.com.

[root@linuxhelp ~]# vim /etc/postfix/main.cf

myhostname = mail.linuxhelp.com
mydomain = linuxhelp.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 192.168.5.0/24, 127.0.0.0/8

 

To Restart the service

[root@linuxhelp ~]# systemctl restart postfix
the servers can be restarted

 

To troubleshoot

[root@linuxhelp ~]#systemctl status postfix
postfix.service - Postfix Mail Transport Agent
Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled)
Active: active (running) since Thu 2016-03-17 23:56:36 EDT; 1min 40s ago
Process: 6424 ExecStop=/usr/sbin/postfix stop (code=exited, status=0/SUCCESS)
Process: 6439 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)

[root@linuxhelp ~]# journalctl -xn

-- Logs begin at Thu 2016-03-17 22:21:47 EDT, end at Fri 2016-03-18 00:01:08 EDT
Mar 18 00:01:01 linuxhelp systemd[1]: Starting Session 13 of user root.
-- Subject: Unit session-13.scope has begun with start-up
...
...
...
-- The start-up result is done.
Mar 18 00:01:01 linuxhelp CROND[6643]: (root) CMD (run-parts /etc/cron.hourly)
Mar 18 00:01:01 linuxhelp run-parts(/etc/cron.hourly)[6649]: start

[root@linuxhelp ~]# postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5
html_directory = no
inet_interfaces = localhost
inet_protocols = all
mail_owner = postfix
.....
.....

 

To test Postfix Mail Servers

Mail User Agent can be used to test the mail servers.

[root@linuxhelp ~]# mail -S "hai" user1@linuxhelp.com
Subject: invite
wellcome to linuxhelp tutoraial...
.
EOT

 

To check if email is received

Go to central mail server and log on as user

[root@linuxhelp ~]# su - user1
[user1@linuxhelp ~]$ mail

Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/user1": 2 messages 1 new 2 unread
U 1 root Thu Mar 17 22:51 21/590 "hai"
>N 2 root Fri Mar 18 00:14 18/606 "invite"
& ^Cinterrupt
You have mail in /var/spool/mail/user1

 

To check the mail content

[user1@linuxhelp ~]$ vim /var/mail/user1

From root@linuxhelp.com Fri Mar 18 00:14:21 2016
Return-Path: <root@linuxhelp.com>
X-Original-To: user1@linuxhelp.com
Delivered-To: user1@linuxhelp.com

...
...

Message-Id: <20160318041421.397E46316722@mail.linuxhelp.com>
From: root@linuxhelp.com (root)
Status: O

welcome to linuxhelp tutorial...

If mail is not received, check root mail spool for error notification.


Thank you! for using Linux Help.

You find this tutorial helpful? Share with your friends to keep it alive.
For more help topics browse our website www.linuxhelp.com
Be the first to comment, we value your suggestions. For further queries please comment below.

Tags: SMTP
user image Author :  Mason