8i | 9i | 10g | 11g | 12c | 13c | 18c | 19c | 21c | Misc | PL/SQL | SQL | RAC | WebLogic | Linux

Home » Articles » Linux » Here

Configure Postfix as an Email Relay on Oracle Linux Servers

This article demonstrates how to configure Postfix as an email relay on Oracle Linux servers. The same process can be used on RHEL and any RHEL clones, such as CentOS.


Having local email relays on your servers can be really useful. Your databases and application servers can send emails using "localhost:25" as the "host:port" combination. Your code doesn't have to worry about authentication or SSL certificates. It's the job of the email relay to worry about how to communicate with the real email servers.

This makes sending emails from the database using UTL_SMTP, UTL_MAIL and APEX_MAIL so much easier.

It is really important you make sure port 25 is blocked on the server's local firewall, so the only processes on the server can access this email relay.

It's important you have a mail server that accepts connections from the relay. You will need to get the details from your email administrator or your hosting provider. You won't be able to the Gmail SMTP servers if you have 2-factor authentication enabled on your Google account, which is a must these days.


Install Postfix and some related packages as the root user.

# OL8
dnf install -y postfix mailx cyrus-sasl cyrus-sasl-plain

# OL7
yum install -y postfix mailx cyrus-sasl cyrus-sasl-plain

Enable and start Postfix.

systemctl enable postfix
systemctl start postfix

Configure the Email Relay

The following operations are performed as the root user. To run from a user with sudo privileges, just prefix with the sudo command.

We will use the following environment variables during the configuration. That way you can just amend the values to suit your SMTP server details, and the rest of the configuration steps can remain unchanged.


The following commands append the mail server connection details to the "/etc/postfix/sasl_passwd" file, then display the contents of the file.

cat >> /etc/postfix/sasl_passwd <<EOF

cat /etc/postfix/sasl_passwd
[smtp.ionos.co.uk]:587    me@example.com:MyPassword

We set the permissions for the file to 600, and use the postmap command to compile and hash the contents of the "sasl_passwd" file, and store them in the "sasl_passwd.db" file under the Postfix configuration directory (/etc/postfix).

chmod 600 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd

Edit the "/etc/postfix/main.cf" Postfix configuration file to set up the mail relay. The following command appends the settings to the end of the existing file. If there are any repetitions of parameter settings, the later settings in the file will override previous settings and warnings will be show in the "/var/logs/maillog" file each time a message is sent.

cat >> /etc/postfix/main.cf <<EOF
# Mail Relay
myorigin = ${MAIL_DOMAIN}
relayhost = [${MAIL_SMTP}]:${MAIL_PORT}
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
# End Mail Relay

If you are editing the file manually, remember to use the values, not the environment variables.

Restart the Postfix service.

systemctl restart postfix

Test It

Issuing the following command on the server sends an email via the local relay.

echo "Test 1 body." | mail -s "Test 1 Subject" me@example.com

For an individual email, we see the following three messages in the "/var/logs/maillog" file. These represent the email being queued, sent, then removed from the queue.

May 25 14:26:10 localhost postfix/qmgr[18778]: 5FD1EB9AA3: from=<tim@oracle-base.com>, size=473, nrcpt=1 (queue active)
May 25 14:26:11 localhost postfix/smtp[18820]: 5FD1EB9AA3: to=<me@example.com>, relay=smtp.ionos.co.uk[]:587, delay=546, delays=545/0.04/0.51/0.19, dsn=2.0.0, status=sent (250 Requested mail action okay, completed: id=1M8QNy-1lpxrP1Cj2-004WYo)
May 25 14:26:11 localhost postfix/qmgr[18778]: 5FD1EB9AA3: removed

If you see errors in the log, take corrective action and try again. Remember to restart the Postfix service if you make any changes to the configuration.

For more information see:

Hope this helps. Regards Tim...

Back to the Top.