LLI Wiki — My Digital Knowledge Base

CentOS: configure Postfix to send mail through an SMTP relay

Setting up Postfix as a send-only mail server on CentOS / RHEL 8, relaying through the SMTP server found in the DNS MX record.

This procedure configures Postfix on CentOS (RHEL 8) as a send-only mail server: local system mail is relayed to the domain's SMTP server, whose address is read from the domain's MX DNS record.

1. Find the SMTP server

Query the MX record of the domain to get the mail server to use as relay:

dig example.com mx

2. Install Postfix and mailx

sudo yum install postfix -y
sudo yum install mailx -y

3. Configure Postfix

The settings are in the following files:

File Purpose
/etc/postfix/main.cf Main Postfix configuration (relay, domain, host name)
/etc/postfix/generic Table used to rewrite sender addresses
sudo vim /etc/postfix/main.cf
sudo nano /etc/postfix/generic

Check the domain and host name used by Postfix:

postconf mydomain
postconf myhostname

4. Create the pickup FIFO and restart Postfix

sudo mkfifo /var/spool/postfix/public/pickup
sudo systemctl restart postfix

5. Check the service and send a test mail

systemctl status postfix
tail -n 10 /var/log/maillog
sudo less /var/mail/$(whoami)
mail -s "Test Email" user@example.com < /dev/null

Notes

Mastodon LLIMastodon SocialFosstodon