How to Linux smtp relay
Published October 20, 2024 · Updated August 26, 2026 · Guides & Tutorials
On a Linux server, sending email reliably usually means configuring a relay — pointing your system's mail through an authenticated SMTP smart host instead of trying to deliver directly. Direct delivery from a Linux box tends to land in spam or get blocked outright. Here is how to set up a Linux SMTP relay the dependable way.
Why relay instead of sending directly
A fresh Linux server has no sending reputation, its IP may be on a shared or blocked range, and port 25 is often filtered. Relaying through an authenticated SMTP smart host solves all three: you inherit a trusted IP, proper authentication, and a port that is not blocked.
How to configure a relay with Postfix
- Install Postfix (the most common Linux mail agent).
- In
/etc/postfix/main.cf, setrelayhost = [your-smtp-host]:587. - Enable SASL authentication and point it at a credentials file with your SMTP username and password.
- Turn on TLS so the connection is encrypted.
- Reload Postfix and send a test with
sendmailormail.
chmod 600), and never expose the relay to the public internet as an open relay. Restrict who can send through it.Choosing between Postfix and alternatives
Postfix is the default on most distributions and the best-documented choice for a relay-only ("null client") setup. Exim and Sendmail exist too, but for a server whose only job is relaying outbound mail through a smart host, Postfix's configuration is simpler and its documentation for exactly this relay-only use case is the most thorough.
Verifying the relay is actually working, not just configured
After reloading Postfix, check /var/log/mail.log (or maillog) for the outbound connection attempt and its result — a successful relay shows a clean handoff to your smart host; an authentication or TLS error will be explicit in that log even when the sending command itself returns no error to the terminal.
A note on firewall interaction
If your relay test fails despite correct Postfix configuration, check that your server's own firewall allows outbound traffic on port 587 — a surprisingly common cause of "correctly configured but not working" relay setups on freshly provisioned Linux servers.
Related reading: have 2 domains on one host · open a google business email account · free email toolsPoint your Linux server at a dedicated SMTP
Dedicated IP, port 587, and SPF/DKIM/DMARC ready — the reliable smart host your Postfix relay needs. From $39.99/mo.
Frequently asked questions
How do I set up an SMTP relay on Linux?
Install Postfix, set relayhost to your SMTP smart host on port 587, enable SASL authentication and TLS, then reload and test.
Why not send email directly from Linux?
Fresh servers lack reputation, may sit on blocked IP ranges, and port 25 is often filtered. Relaying through an authenticated smart host is far more reliable.
What smart host should I use?
A dedicated SMTP with its own IP and full authentication — it gives your Linux relay trusted delivery and no daily caps.