Menu

Configure Postfix SMTP Relay (Smart Host) on CentOS 8


Postfix is a Mail Transport Agent (MTA), which can be easily configured as a private relay host, passing mail to other mail servers. Unlike Sendmail, Postfix is considered a very secure MTA, offering a high level of flexibility and ease of administration.
In this article, I am configuring Postfix on CentOS 8 as SMTP smart host (relay host) using SASL authentication to send out mail.

1. Install Postfix

Postfix should be preinstalled on CentOS 8 by default. If for some reason you don’t have the service installed, use the below command to install the relevant package:

[ ~]# dnf install postfix

2. Install SASL plugin

Package cyrus-sasl-plain contains the Cyrus SASL plugins which support PLAIN and LOGIN authentication.

[ ~]# dnf install cyrus-sasl-plain

3. Edit the configuration file

I am configuring the service to act as SMTP smart host, sending the mail to hackthesec mail server, which is my ISP mail server, using SASL authentication (login and password).

Edit /etc/postfix/main.cf configuration file and update the below relevant lines:

...
meta_directory = /etc/postfix
myhostname = chronos
mydomain = hackthesec.co.in
local_transport = error: this is a null client
myorigin = $myhostname.$mydomain
# list of trusted network addresses, that can relay through this MTA
mynetworks = 127.0.0.0/8 [::1]/128
relayhost = [hackthesec.co.in]
disable_dns_lookups = yes

# SASL authentication 
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = static:admin@hackthesec.co.in:mypassword
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt
...

4. Test the configuration

Test the configuration for any obvious errors. If the configuration is correct, the below command should not give any output:

[ ~]# postfix check

5. Start and enable Postfix service

Launch and enable Postfix daemon:

[ ~]# systemctl start postfix
[ ~]# systemctl enable postfix

6. Test the e-mail delivery

Verify the configuration by sending the test e-mail from the command line.
Prepare test e-mail body:

[ ~]# echo "Subject: Mail Delivery Test" > /tmp/mail.txt
[ ~]# echo "This is the example e-mail body" >> /tmp/mail.txt

Send the test e-mail using sendmail script with increased verbosity:

[ ~]# sendmail -v admin@hackthesec.co.in < /tmp/mail.txt

Monitor the system journal to check if the e-mail was successfully relayed to the mail server:

[ ~]# journalctl -u postfix

Last but not least – check the recipient’s Inbox (or SPAM box), the test e-mail should be delivered successfully.

If for some reason the e-mail has not arrived yet, you can display mail queue on your relay host:

[ ~]# mailq


About Author:


I am a Linux Administrator and Security Expert with this site i can help lot's of people about linux knowladge and as per security expert i also intersted about hacking related news.TwitterFacebook

Next
Newer Post
Previous
Older Post

0 comments:

Post a Comment

 
Top