Skip to main content
  1. Knowledge base
  2. Findings
Check: email.smtp.open_relay

How to Fix an Open Mail Relay on Your SMTP Server

To fix an open mail relay, restrict your SMTP server so it only accepts mail for domains it hosts, or from clients that authenticate or come from trusted networks. Then re-test with an external sender and recipient: the server must reject the RCPT TO command with a 5xx error instead of accepting it.

An open mail relay is an SMTP server that accepts mail from any sender for any destination and forwards it without checking who is asking. Every mail server must receive mail for its own domains. A relay is open when it also sends mail on behalf of strangers.

What causes an open relay?

Almost every open relay is a configuration mistake, not a software bug. Common causes:

  • Over-broad trusted networks. Postfix's mynetworks or an Exim relay host list contains a wide range such as 0.0.0.0/0, or a whole cloud subnet shared with other tenants.
  • Missing recipient checks. The server never compares the recipient domain against the domains it is responsible for, so it accepts every RCPT TO.
  • Migration leftovers. Someone adds a permissive rule to get a printer, CRM or legacy app sending mail and never removes it.
  • A backup MX that accepts everything. A secondary MX without a list of valid recipients accepts and queues mail for any address, which also produces backscatter.
  • Vendor defaults. Some appliances and older installs ship in permissive mode. Check your vendor's documentation, because defaults vary by product and version.

Why is an open relay rated critical?

Spammers and phishers scan the internet continuously for relays. Once yours is found, abuse starts fast and hurts in several ways:

  1. Your IP address gets blocklisted. Legitimate mail from the same server or network starts bouncing or landing in spam.
  2. Phishing goes out through your infrastructure. Messages carry your relay's IP and hostname, and can claim your domain in the envelope sender.
  3. Resources run out. Queues fill, disks fill, and bandwidth goes to mail you never meant to send.
  4. You pay for cleanup and lost reputation. Delisting takes days of requests, and customers or partners may start treating your mail as untrusted.

The severity is critical because exploitation needs no credentials and no special skill, and your reputation takes the damage immediately. An auditor will also read an open relay as proof that a public service has no basic access control.

TLS hardening is a separate problem from relaying. A relay that requires authentication can still be exposed to STARTTLS stripping that lets an attacker read your mail. Fix the relay first, then harden transport.

How do I fix an open mail relay in Postfix?

The goal is the same on every MTA: accept a recipient only if the client is trusted or authenticated, or the recipient domain is one you host. In Postfix, put this in main.cf:

# Only local loopback is trusted. Do not list broad ranges.
mynetworks = 127.0.0.0/8 [::1]/128

# Domains this server is the final destination for
mydestination = $myhostname, localhost.$mydomain
virtual_mailbox_domains = example.com

# Relay only for trusted clients or authenticated users;
# reject everything else that is not for a local domain.
smtpd_relay_restrictions =
    permit_mynetworks,
    permit_sasl_authenticated,
    defer_unauth_destination

Then reload and check the effective values:

sudo postfix check
sudo postfix reload
postconf mynetworks smtpd_relay_restrictions

Other MTAs follow the same idea with different syntax:

  • Exim: set acl_smtp_rcpt so that the final rule is deny, with accept rules only for authenticated senders, trusted hosts, and local domains.
  • Sendmail: review the access database and the relay-related features.
  • Microsoft Exchange: inspect Receive connectors and remove anonymous relay permissions that are broader than needed.

Trusted applications that must send mail should authenticate on the submission port (587 with STARTTLS, or 465) instead of relying on IP-based trust. If you must trust an IP, list a single address, not a subnet.

How does the scanner detect and rate an open relay?

SetEnforce's scan checks each MX host of the domain. It connects on port 25 and plays the start of an SMTP conversation using a sender and recipient that are both outside the domain under test. If the server answers the RCPT TO command with a 2xx acceptance, the check fails. If it answers with a 5xx rejection (or a 4xx deferral), the check passes. The evidence recorded is the server's response line, which shows which command was accepted.

The scan rates a confirmed open relay as critical, the highest severity. If a host cannot be reached on port 25, the result is reported as not tested, not as passed. Some networks block outbound port 25, so an unreachable result does not prove the server is safe.

Your server's behaviour is the real test. Reproduce what the scanner does:

nc -C mail.example.com 25

Then type the following lines one at a time (use addresses at domains you do not host):

EHLO test.example.net
MAIL FROM:<[email protected]>
RCPT TO:<[email protected]>
QUIT

A fixed server answers the RCPT TO line with something like 554 5.7.1 Relay access denied or 454 4.7.1 Relay access denied. Any 250 reply to that RCPT TO line means the relay is still open. The exact wording varies by MTA. Stop after RCPT TO and do not send DATA, so no message is ever delivered.

How do I confirm the fix on re-scan?

  1. Run the manual test above from a machine outside your trusted network. A test from the server itself proves nothing, because local clients are usually trusted.
  2. Test every MX host listed for the domain, including backup MX hosts.
  3. Check the mail logs for the test attempt and confirm the rejection was logged.
  4. Re-run the scan from SetEnforce. The finding should clear on the next run, and the evidence line should show the rejection.
  5. If your IP was blocklisted while the relay was open, request delisting only after the fix is confirmed. Most blocklists re-test before removing an entry.

If the result stays failed, look for a second MX host or a load balancer that forwards port 25 to a different, still-permissive server. Once relaying is closed, also consider anchoring TLSA records in a DNSSEC-signed zone so that the transport to your MX can't be silently downgraded.

For the protocol background, see the SMTP specification in RFC 5321.

Common questions

Is an open relay the same as an open resolver?

No. An open relay is an SMTP server that forwards mail for strangers. An open resolver is a DNS server that answers recursive queries from anyone. Attackers abuse both because they are misconfigured public services, but the protocols, ports, and fixes differ.

Can I leave relaying open on an internal network?

Only if you control and limit that network. Trust specific host addresses, not entire ranges, and prefer authenticated submission. Cloud and shared networks often include machines you do not control, and one compromised host on a trusted subnet is enough to turn an internal relay into a spam source.

How long until my reputation recovers after closing a relay?

It depends on the blocklists involved and how much was sent. Many lists expire entries automatically once abuse stops, while others require a manual delisting request. Fix the relay first and confirm it, because requests made while the server is still open are usually refused or reversed.

Key takeaways

  • An open relay accepts mail for any recipient from any client. The fix is to accept recipients only for your own domains, trusted hosts, or authenticated users.
  • Trusted network lists are the most common cause, so keep them as narrow as a single address.
  • Test from outside your network, against every MX host, and stop at RCPT TO so nothing is delivered.
  • SetEnforce checks each MX host for an accepted external recipient and clears the finding once the server rejects it.
  • After relaying is closed, harden transport with DANE or MTA-STS and monitor with TLS-RPT.

Check whether your own domain gets this right. Scanning is free and needs no account.

Scan your domain

All articles