Candid photograph of a Linux server terminal with a soft olive-green glow against a dark slate background, conveying a calm technical atmosphere.

Step-by-step guides for system administrators — covering command-line basics, web server setup, and preparation material for technical interviews.

Browse Tutorials

How to Set Up an SMTP Relay with Postfix on CentOS

An SMTP relay accepts messages from local applications and passes them to an authenticated external service. Configuring Postfix this way on CentOS avoids direct delivery from an Australian home or office connection, where many ISPs block outbound port 25 and residential IP addresses have poor sending reputations.

This guide uses CentOS Stream 9, Postfix 3.x and an SMTP provider’s submission service on TCP port 587. It creates a relay client rather than an open relay: only the CentOS host can submit messages, while the provider handles recipient delivery, SPF and DKIM for authorised domains.

Choose the relay architecture

First decide whether Postfix is a local submission point for applications or a network-facing mail server. The configuration below is for an outbound relay: applications submit on the loopback interface, Postfix queues the messages and sends them through the provider. It does not publish a public relay for arbitrary senders.

Choose a provider before editing Postfix. Record its submission hostname, port, username and whether it expects an app-specific password. Australian teams can compare providers serving the local market, including some with support or endpoints in Sydney and Melbourne, but should test latency and quotas rather than assume local hosting is faster.

Give the server a stable identity such as mail.example.com.au, and authorise the corresponding .com.au business domain with the provider. Set the system timezone to Australia/Sydney or Australia/Melbourne for accurate daylight-saving transitions and easier log correlation.

Install Postfix on CentOS Stream

CentOS Linux 7 is end-of-life, so use CentOS Stream 9 or a supported RHEL-compatible release for a new deployment. Install Postfix and its Cyrus SASL client module, then confirm that SASL support is available.

sudo dnf install -y postfix cyrus-sasl-plain
sudo systemctl enable --now postfix
postconf -a

Limit Postfix to the loopback interface unless it must accept mail from other hosts. Replace the example domain with the real internal or business domain; a public DNS record is not essential for an outbound-only relay, although a fully qualified hostname improves logs and diagnostics.

sudo postconf -e 'myhostname = mail.example.com.au'
sudo postconf -e 'mydomain = example.com.au'
sudo postconf -e 'myorigin = $mydomain'
sudo postconf -e 'inet_interfaces = loopback-only'

Configure the authenticated smarthost

Use the provider’s submission service on port 587 with STARTTLS unless its documentation specifically requires implicit TLS on port 465. The square brackets around the provider hostname prevent Postfix from performing an MX lookup and ensure the connection goes directly to the supplied server.

Store the relay settings in /etc/postfix/main.cf. The verify TLS level requires a valid certificate, while the bundled CentOS trust store validates the provider’s certificate authority.

sudo postconf -e 'relayhost = [smtp.provider.com.au]:587'
sudo postconf -e 'smtp_sasl_auth_enable = yes'
sudo postconf -e 'smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd'
sudo postconf -e 'smtp_sasl_security_options = noanonymous'
sudo postconf -e 'smtp_tls_security_level = verify'
sudo postconf -e 'smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt'

Create /etc/postfix/sasl_passwd with the exact bracketed relay key and the provider login. The username may be a full email address, and many providers issue a separate app password for server authentication.

[smtp.provider.com.au]:587 postmaster@example.com.au:app-password

Build the lookup database and restrict access to the credential files. On SELinux-enabled CentOS systems, restore the expected security context.

sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
sudo chown root:postfix /etc/postfix/sasl_passwd.db
sudo chmod 640 /etc/postfix/sasl_passwd.db
sudo restorecon -Rv /etc/postfix

Test mail delivery and logs

Validate the configuration before sending customer or application mail. Reload Postfix, submit a message to a mailbox you control and watch the delivery attempt.

sudo postfix check
sudo systemctl reload postfix
printf 'Subject: CentOS relay test\n\nRelay verification.\n' | sudo /usr/sbin/sendmail -v -f sender@example.com.au admin@example.net

Follow /var/log/maillog with sudo tail -f /var/log/maillog, or use sudo journalctl -u postfix -f on a journald-based host. A 535 response indicates rejected SASL credentials, while certificate errors point to the provider hostname or CA bundle. Temporary 4xx responses usually mean the provider is deferring delivery, so inspect the queue with postqueue -p.

A successful message should contain the provider’s DKIM signature and an SPF result aligned with the authorised domain. Check the original headers, not just the visible body. If the provider uses port 465 instead, its instructions will require a wrapper-mode TLS configuration rather than STARTTLS on 587.

Secure and maintain the relay

Keep the relay closed by retaining loopback-only listening and the default recipient restrictions. Never set mynetworks to 0.0.0.0/0 or blank relay_recipient_maps on a public server. Permit outbound access to port 587, but do not open inbound port 25 unless the host genuinely receives internet mail. Remote applications should use authenticated submission or a narrowly defined private network.

For commercial messages, follow the Australian Spam Act 2003 requirements for consent, sender identification and unsubscribe functionality. Monitor the queue, disk space and failed-delivery logs, and rotate provider app passwords on a defined schedule. Keep the credential map out of unencrypted backups. When adapting these instructions or reusing related material, follow the site’s copyright policy.

After reviewing the settings on a staging copy of the production configuration, the concrete next action is to run sudo postfix check && sudo systemctl reload postfix.