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
[root@hackthesec ~]# dnf install postfix
2. Install SASL plugin
Package cyrus-sasl-plain contains the Cyrus SASL plugins which support PLAIN and LOGIN authentication.
[root@hackthesec ~]# 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:
[root@hackthesec ~]# postfix check
5. Start and enable Postfix service
Launch and enable Postfix daemon:
[root@hackthesec ~]# systemctl start postfix
[root@hackthesec ~]# 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:
[root@hackthesec ~]# echo "Subject: Mail Delivery Test" > /tmp/mail.txt
[root@hackthesec ~]# echo "This is the example e-mail body" >> /tmp/mail.txt
Send the test e-mail using sendmail script with increased verbosity:
[root@hackthesec ~]# 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:
[root@hackthesec ~]# 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:
[root@hackthesec ~]# mailq
0 comments:
Post a Comment