Many servers only need to send email: password resets from an app, cron job output, monitoring alerts. A Postfix send-only SMTP server does that without running a full mail system or accepting mail from the internet. This guide sets it up securely and covers the DNS records that keep your messages out of spam.
Before you start
- A Linux VPS with root access and a fully qualified hostname such as
server1.example.comwith an A record. - Outbound port 25 allowed by your provider, or an external SMTP relay account (port 587).
- Access to the DNS zone of the sending domain.
Install Postfix
- Ubuntu/Debian:
sudo apt install -y postfix mailutilsChoose Internet Site and enter your domain as the system mail name.
- AlmaLinux/Rocky:
sudo dnf install -y postfix s-nail && sudo systemctl enable --now postfix
Make Postfix send-only
- Edit
/etc/postfix/main.cfand set:myhostname = server1.example.com myorigin = example.com inet_interfaces = loopback-only inet_protocols = all mydestination = localhost smtp_tls_security_level = mayinet_interfaces = loopback-onlymeans only programs on this server can submit mail – nothing from the internet. - Restart and confirm it listens only on localhost:
sudo systemctl restart postfix && ss -tlnp | grep ':25'
Send a test email
echo 'Test body' | mail -s 'Postfix test' you@yourmail.comWatch the log with sudo journalctl -u postfix -f (or /var/log/mail.log / /var/log/maillog). Look for status=sent.
Set up DNS for deliverability
- PTR (reverse DNS): ask your provider (or use their panel) to set the server IP's PTR to
server1.example.com. - SPF: add or update a TXT record on
example.com, for examplev=spf1 ip4:203.0.113.10 ~all. Merge with any existing SPF – a domain must have only one. - DKIM: install OpenDKIM, generate a key and publish its TXT record, then connect it to Postfix with
miltersettings. - DMARC: start with
v=DMARC1; p=none; rua=mailto:dmarc@example.comon_dmarc.example.com.
Alternative: relay through an SMTP provider
If port 25 is blocked or your IP has poor reputation, relay via a transactional email service or your mailbox provider on port 587:
- Add to
main.cf:relayhost = [smtp.provider.com]:587 smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous smtp_tls_security_level = encrypt - Create
/etc/postfix/sasl_passwdcontaining[smtp.provider.com]:587 username:password, then:sudo chmod 600 /etc/postfix/sasl_passwd && sudo postmap /etc/postfix/sasl_passwd && sudo systemctl restart postfix - Use the provider's SPF/DKIM instructions for your domain.
Troubleshooting
- Connection timed out to port 25: the provider blocks outbound SMTP. Request unblocking or use a relay.
- Mail lands in spam: check PTR, SPF, DKIM and DMARC, and test your IP on blocklists.
- Queue grows: view with
postqueue -p, retry withpostqueue -f, and read the deferral reason in the log. - "Relay access denied": an app tried to submit from another host; send via localhost instead.
FAQ: Postfix send-only server
Will this server receive email?
No. With loopback-only it accepts mail only from local programs. Keep MX records pointed at your real mail host.
Can a PHP app use it?
Yes. PHP's mail() uses sendmail, which Postfix provides, or point an SMTP library at localhost:25.
Is a relay better than sending directly?
For important transactional mail, a reputable relay usually delivers more reliably than a fresh VPS IP.
