top of page
Recent Posts
Writer's pictureMunshi Hafizul Haque

How to install and configure SMTP (Postfix) In Red Hat Enterprise Linux 7

The Simple Mail Transfer Protocol (SMTP) is a communication protocol for electronic mail transmission. The most commonly used implementations of SMTP in most Linux distributed OS are Sendmail and Postfix.


Postfix is an open source mail-transfer agent that was originally developed as an alternative to Sendmail and is usually set up as the default mail server. Let's start with Postfix.


Step:1 To verify the /etc/hosts file.

# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain
::1     ip6-localhost ip6-loopback
192.168.122.144	mail.lab.munshibari.biz	mail

Step:2 To install Postfix rpm's or packages.

# yum install -y postfix

Step:3 To configure the Postfix as required.

# vi /etc/postfix/main.cf
::::::::::::: CUT SOME OUTPUT ::::::::::::: 
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
# Hostnames normally have prefixe Server
myhostname = loadbalancer.lab.munshibari.biz
# The domain that is actually handling mail
mydomain = lab.munshibari.biz
inet_interfaces = localhost , $myhostname
inet_protocols = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
unknown_local_recipient_reject_code = 550
#  The list of trusted remote SMTP servers that can relay through the server
mynetworks_style = subnet
mynetworks = 192.168.122.0/24, 127.0.0.0/8
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
 
  
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
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.10.1/samples
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES

::::::::::::: CUT SOME OUTPUT ::::::::::::: 

Step:4 If Firewalld service is running, Need to open the ports in the OS firewall using following firewall-cmd commands.

# firewall-cmd --add-port=25/tcp --permanent
# firewall-cmd --reload

Step:5 To start the Postfix service.

# systemctl restart postfix
# systemctl enable postfix

Step:5 To verify the Postfix (SMTP) service from the client.

# telnet 192.168.122.144 25
Trying 192.168.122.144...
Connected to 192.168.122.144.
Escape character is '^]'.
220 loadbalancer.lab.munshibari.biz ESMTP Postfix
HELO  lab.munshibari.biz
250 loadbalancer.lab.munshibari.biz
MAIL FROM: root@lab.munshibari.biz
250 2.1.0 Ok
RCPT TO: atower@lab.munshibari.biz
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
Subject: This is a test message 

Hello,

This is a test message
.
250 2.0.0 Ok: queued as A611340B196
quit
221 2.0.0 Bye
Connection closed by foreign host.

To check email from Postfix (SMTP) server by login with users.

# yum install mailx
# su - atower
$ mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/atower": 1 message 1 new
>N  1 root@lab.munshibari.  Mon Jul 27 14:49  13/444   "This is a test message"
&
Message  1:
From root@lab.munshibari.biz  Mon Jul 27 14:49:33 2019
Return-Path: <root@lab.munshibari.biz>
X-Original-To: atower@lab.munshibari.biz
Delivered-To: atower@lab.munshibari.biz
Subject: This is a test message 
Status: R

Hello,

This is a test message
& 

This is a basic smtp email server configuration and will post some advanced configuration as well.

21 views0 comments

Recent Posts

See All

コメント


Log In to Connect With Members
View and follow other members, leave comments & more.
bottom of page