Learn to Install and Configure Postfix on Oracle Linux
Introduction
This tutorial shows you how to install and set up the Postfix email server software on an Oracle Linux system to enable you to send messages within your network. This tutorial is targeted at users of Oracle Linux 8 or later.
Postfix is a Mail Transfer Agent (MTA) server that was developed as a replacement for sendmail
, which is the default MTA server on many older Linux systems. Because of its modular pipeline-based architecture, Postfix is versatile and integrates easily with many other services, such as spam and anti-virus processing, as well as with message store software, such as the Dovecot IMAP and POP server.
This tutorial describes how to set up and configure Postfix to function primarily as a Simple Mail Transfer Protocol (SMTP) server.
Note: After completing this tutorial, you can optionally configure domain level validation using technologies such as DomainKeys Identified Email (DKIM), Sender Policy Framework (SPF), and Domain Message Authentication Reporting (DMARC) to enhance email security.
Objectives
Upon completion of this Lab you will be able to:
- Set the server host name
- Install Postfix with appropriate firewall rules
- Configure Postfix to send unencrypted email
- Send test emails by using
mailx
- Review the Postfix mail queue
Prerequisites
- Any system with Oracle Linux 8 or later
Install Postfix
-
Install the
postfix
package on your instance by using the package manager, as follows:sudo dnf install -y postfix
-
Allow SMTP traffic through the server firewall:
sudo firewall-cmd --zone=public --add-service=smtp --permanent
sudo firewall-cmd --reload
-
Remove the
sendmail
package, if it is present:sudo dnf remove -y sendmail
-
Set Postfix as the default Mail Transfer Agent:
sudo alternatives --set mta /usr/sbin/sendmail.postfix
-
Enable and start the Postfix service:
sudo systemctl enable --now postfix
Configure Postfix
-
Create a backup for the default Postfix configuration:
sudo mv /etc/postfix/main.cf /etc/postfix/main.cf.bak
-
Edit the configuration file,
/etc/postfix/main.cf
, to contain lines similar to the following:sudo tee -a /etc/postfix/main.cf > /dev/null <<EOF myhostname = $(hostname -f) myorigin = \$myhostname inet_interfaces = all inet_protocols = all mydestination = \$myhostname, localhost mynetworks = 192.168.1.0/24, 127.0.0.0/8, 10.0.0.0/24 EOF
Note: Sending emails from a single host is sufficient for the purpose of this lab. In a production environment, you should set
mydomain
as the registered domain name from which you intend to send email. For more information, read the Postfix manual pages. -
Restart the Postfix service:
sudo systemctl restart postfix
Send Test Emails
-
Install the
mailx
email client:sudo dnf install -y mailx
-
Send a test email to your own external email address. Update the hostname in the
mailx
command to match the instance from which you are sending email:hostname=$(hostname -f)
echo "External email" | mailx -r root@$hostname -s "Test email subject" admin@example.com
Note: Using
mailx
to send test emails from a single host is sufficient for the purpose of this lab. In a production environment, you should use the registered domain that you configured in/etc/postfix/main.cf
within the sender email address instead, for exampleroot@example.com
. -
Check your own email account for a new message. You may need to check your spam folder.
-
If the email does not appear, you can check the Postfix mail queue:
sudo mailq
-
You can also check the Postfix log. Press Ctrl + C to exit:
sudo tail -f /var/log/maillog
For more information:
- Postfix project page at https://www.postfix.org/
postfix(1)
manual page- Oracle Linux Documentation
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.
Learn to Install and Configure Postfix on Oracle Linux
F47604-09
March 2024
Copyright © 2021, Oracle and/or its affiliates.