An open relay mail server accepts mail from anyone and forwards it to any destination, which lets spammers send through your IP address until it lands on blocklists. You stop an open relay in Postfix by allowing relaying only for trusted networks and authenticated users, and by making smtpd_relay_restrictions end with reject_unauth_destination. Modern Postfix is closed by default, so an open relay almost always comes from a configuration change someone made.
This guide shows the correct restriction order, how to test your server from outside, and how to detect abuse of legitimate accounts, which is the more common problem today.
A mail server has two jobs. It accepts mail for its own domains (delivery), and it forwards mail on behalf of its own users to the world (relaying). An open relay forwards mail for strangers to strangers. Spammers scan the internet for them, and within hours your server can send thousands of messages, your IP lands on blocklists, and legitimate mail from your domain starts to bounce.
Today most abuse is different: an attacker guesses or steals a real user's password and sends through the authenticated submission port. The same hardening steps below limit both.
Postfix checks each recipient with smtpd_relay_restrictions (since Postfix 2.10), then smtpd_recipient_restrictions. A secure baseline in main.cf:
Read it in order:
permit_mynetworks allows clients whose IP is in mynetworks.permit_sasl_authenticated allows clients who logged in.reject_unauth_destination rejects everything that is not for a domain the server is responsible for.The final reject_unauth_destination is the line that closes the relay. Without it, and with no other rule rejecting, mail may be accepted for any destination.
mynetworks is a list of IP ranges that may relay without a password. The classic open relay is a wide value:
Even a wide private range such as a whole cloud subnet is risky, because any compromised host on it can send mail. Keep mynetworks to localhost, and use mynetworks_style = host if you want the safe default described in the Postfix documentation. Everything else should authenticate.
Users should submit mail on port 587 (STARTTLS) or 465 (implicit TLS) and log in. Port 25 is for server-to-server delivery. In master.cf:
The last two lines make the port accept only logged-in users, so even a mistake elsewhere cannot open it. For the SASL backend, Postfix normally hands authentication to Dovecot with smtpd_sasl_type = dovecot and smtpd_sasl_path = private/auth.
Test from a machine outside your own network, so you are not trusted by mynetworks. Use swaks (a scriptable SMTP test tool):
A safe server answers the RCPT TO with a rejection:
If you see 250 2.1.5 Ok for a domain that is not yours, you are an open relay. Also check the server's own view of its configuration:
Public checkers also exist, but test yourself first so you do not depend on a third party.
Closing the relay does not stop a user whose password was stolen. Add these layers:
SASL ... authentication failed in the mail log.main.cf:| Setting | Why |
|---|---|
smtpd_helo_required = yes | Rejects clients that skip the SMTP greeting |
disable_vrfy_command = yes | Stops address harvesting with VRFY |
smtpd_tls_security_level = may on port 25 | Encrypts server-to-server mail when the peer supports it |
reject_non_fqdn_recipient | Rejects malformed recipient addresses |
reject_unknown_recipient_domain | Rejects recipient domains that do not exist in DNS |
Make changes with postconf -e, validate with postfix check, and apply with postfix reload.
sudo postfix stop, or hold the queue with postsuper -h ALL to preserve evidence.sasl_username= fields.No. The default smtpd_relay_restrictions permit only trusted networks and authenticated users and reject other destinations. An open relay comes from a misconfigured mynetworks or restriction list.
Yes. Authenticated relaying is not an open relay. Only unauthenticated relaying for strangers is.
You will see bounces that name a blocklist, and lookup sites will list your IP. The cause must be fixed before requesting removal.
It stops anonymous relaying, but not misuse of valid accounts. Rate limits and monitoring cover that part.
Keep mynetworks narrow, end smtpd_relay_restrictions with reject_unauth_destination, and require authentication on submission ports. Test from outside with swaks, add rate limits and failed-login blocking, and watch the queue and logs so you notice a stolen account before the blocklists do.