What is the difference between an open SMTP relay and a mail server that relays only for authenticated clients or trusted networks?
answer
- who may send to outside domains
- final destination versus forwarding on
- trusted networks, authenticated clients, served domains
- decided at RCPT time
- blocklists punish the relay's own address
basics
~20 sAn open relay accepts mail from any client for any destination. A correctly run MTA relays to outside domains only for authenticated clients or trusted networks, and accepts everything else only for domains it serves.
solid answer
~50 sRelaying means accepting a message for a domain the server is **not** the final destination for, and passing it on. RFC 5321 lets a relay refuse that task for policy reasons, with `550` as the suggested reply, and §7.9 records that relaying through arbitrary sites was used to hide where mail came from. A correctly run MTA grants relay to clients on **trusted networks** (Postfix's `mynetworks`), to **authenticated** clients (`permit_sasl_authenticated`), and to destination domains it is configured to forward for. It accepts mail from anyone else only for domains it is the final destination for, and decides this at `RCPT TO`. An **open relay** applies none of these checks. Bulk senders hide behind it, and its IP address ends up on DNS blocklists, so its own legitimate mail is refused. Postfix's default `smtpd_relay_restrictions` is `permit_mynetworks, permit_sasl_authenticated, defer_unauth_destination`.
code
ini · 6 lines# Postfix main.cf: relay policy (Postfix 2.10 and later)
mynetworks = 127.0.0.0/8 [::1]/128 192.0.2.0/28
smtpd_relay_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destinationgo deeper
Know the definition: an open relay forwards mail from anyone to anywhere. A safe server relays outward only for trusted networks or authenticated clients, and otherwise accepts mail only for its own domains.
Explain where the decision happens (at RCPT TO), the three ways to grant relay, and Postfix's default smtpd_relay_restrictions with permit_mynetworks, permit_sasl_authenticated and defer_unauth_destination.
Show how servers become open relays by accident: a wide mynetworks, a local proxy that makes clients look trusted, mixed relay and spam lists. Then test from outside after every change.
Decide relay trust centrally: which systems may relay at all, whether they authenticate rather than rely on IP ranges, and who reviews the rule set before deployment.
## What relaying means An SMTP server that receives a message is in one of two roles for each recipient: - **Final destination**: it hosts the recipient's domain and delivers locally, or hands the message to the mailbox system. - **Relay**: it accepts the message and then acts as an SMTP client itself, passing the message to the next server. RFC 5321 §3.6.2 describes a relay as usually the target of an MX record, which may accept or reject the task of relaying "in the same way it accepts or rejects mail for a local user". If it declines for policy reasons, a `550` reply SHOULD be returned. Relaying itself is legitimate. An organisation's outbound mail normally passes through its own relays, and an inbound gateway relays to the mailbox system behind it. The question is **for whom** a server relays. ## Three legitimate ways to grant relay | Grant | What the server trusts | Postfix control | Main risk | |---|---|---|---| | Trusted network | The client's IP address is in a listed range | `mynetworks` with `permit_mynetworks` | A range drawn too wide trusts hosts you do not run | | Authenticated client | The client proved an identity during the session | `permit_sasl_authenticated` | A stolen credential becomes a relay ticket | | Served destination | The recipient domain is one the server forwards for | `relay_domains` (checked by `reject_unauth_destination`) | A domain listed by mistake | Any recipient that matches none of these is refused at `RCPT TO`. In Postfix 2.10 and later the relay rules live in `smtpd_relay_restrictions`, whose default is `permit_mynetworks, permit_sasl_authenticated, defer_unauth_destination`. The last item refuses unauthorised destinations with a temporary code. `reject_unauth_destination` refuses them permanently, with `554` by default (`relay_domains_reject_code`), even though RFC 5321 suggests `550`. How a client authenticates (the mechanisms, and TLS before credentials) is covered with submission authentication. ## Why an open relay ends up blocklisted An **open relay** forwards mail from any client to any destination. RFC 5321 §7.9 notes that relaying through arbitrary sites was used "as part of hostile efforts to hide the actual origins of mail", and that implementations SHOULD let sites limit relaying to known or identifiable sources. Postfix's relay documentation puts the outcome plainly: spammers abuse servers that forward mail from arbitrary systems, and abused systems end up on anti-spam denylists. For the operator, the damage arrives in this order: 1. Unsolicited mail leaves through the server, and its IP address appears in the `Received` fields of every message. 2. Receivers' complaints and traps get that address listed on DNS blocklists. 3. Receivers that consult those lists refuse **all** mail from the address, including the organisation's own invoices and password resets. 4. Closing the relay does not lift the listings by itself; each list has its own removal process, and the queue fills with bounces in the meantime. ## How relay control fails in practice Few servers are installed as open relays. Most become one through a configuration that trusts too much: - **A trusted range drawn too wide.** Postfix's `mynetworks_style` defaults to `host` from Postfix 3.0, so only the local machine is trusted. Before 3.0 the default was `subnet`, and the `class` style can trust "your entire provider's network", as the documentation warns. - **Every connection appearing local.** If a proxy or filter on the same host hands connections to the MTA, every client can arrive from a loopback address that `permit_mynetworks` trusts. - **Relay and spam rules mixed together.** Before Postfix 2.10, both lived in `smtpd_recipient_restrictions`. A `PERMIT` written for a spam exception, such as allowing one odd `HELO` name, also granted relay to every client that sent that name. That made the server an open relay for those clients. - **Applications that relay for others.** A web form that lets visitors choose the recipient turns a trusted application server into a relay one layer up. ## Checking your own server Test from the outside, the way a stranger would connect: 1. From a host outside your trusted ranges, without authenticating, send an ordinary test message to an address in a domain your server does not serve. The server must refuse that recipient at `RCPT TO`. 2. From the same host, send to one of your own domains. It must be accepted. Refusing it would break inbound mail. 3. From a trusted or authenticated client, send to an outside domain. It must be accepted. 4. Read the MTA's log for each test, and keep the test after every configuration change. While you trial new restrictions, Postfix's `soft_bounce = yes` turns permanent rejections into temporary ones, so mistakes leave mail queued instead of bounced.
- Why did Postfix 2.10 split smtpd_relay_restrictions out of smtpd_recipient_restrictions?Before 2.10, relay permission and spam blocking shared one list. A `PERMIT` written as a spam exception could grant relay too. Postfix's documentation shows a `HELO` exception that made the server an open relay for every host using that name. With a separate relay list, a permissive spam policy no longer widens relay rights.
- Is relaying by trusted network still a sound choice for internal application servers?It works, but it trusts every host in the range, including a compromised one. Keep the range to the exact hosts or a small subnet, or have the applications authenticate so each sender is identifiable and can be revoked. Either way, test that the range does not include a proxy that makes outside clients look local.
- Which reply code should a server use when it refuses to relay?RFC 5321 says a relay that declines for policy reasons SHOULD return `550`. Postfix's `reject_unauth_destination` uses `554` by default (`relay_domains_reject_code`). Its default relay list ends with `defer_unauth_destination`, which refuses with a temporary code instead, so a configuration mistake leaves the client retrying rather than bouncing the message.
- Requiring STARTTLS on port 25 stops a server being an open relay.
- Any server that accepts mail from the Internet is an open relay.
- Trusting the provider's whole network range in mynetworks is harmless.
- RFC 5321 obliges a server to relay mail for any client that asks.
- In Postfix, a spam-exception PERMIT can never widen relay rights.