To configure Postfix to relay through a smarthost, set relayhost to the provider's SMTP server, enable SASL authentication and TLS for outgoing connections, and store the credentials in a hashed sasl_passwd map. A Postfix smarthost relay sends all outgoing mail through a trusted server such as Amazon SES, Mailgun or your ISP, instead of delivering directly from your own IP address.
This is useful when your host blocks port 25, when your IP has a poor reputation, or when you want your own mailbox server but an ESP's deliverability. The example uses a placeholder provider, smtp.provider.example on port 587. Take the real host, port and credentials from your provider.
A smarthost (also called a relay host) accepts mail from your server and delivers it onward. Postfix still receives mail and queues it, but it hands outgoing messages to the smarthost over an authenticated, encrypted connection.
Use a smarthost when:
A smarthost does not remove the need for SPF and DKIM. Add the provider's SPF include to your SPF record, and sign mail with your own key or with the key the provider asks you to publish. Check the provider's domain verification steps first.
The relay is set with relayhost. Putting the name in square brackets stops Postfix doing an MX lookup, so it connects straight to the host.
The values mean:
| Parameter | Effect |
|---|---|
relayhost | Where all outgoing mail goes. Brackets disable MX lookup. |
smtp_tls_security_level = encrypt | Postfix refuses to send over an unencrypted connection. |
smtp_tls_CAfile | Trusted certificate authorities, so the relay certificate can be checked. |
smtp_tls_protocols | Disallows old TLS versions. |
For port 465 (implicit TLS) use smtp_tls_wrappermode = yes together with smtp_tls_security_level = encrypt. Port 587 uses STARTTLS and needs no wrapper mode. With encrypt, Postfix verifies that TLS works but does not check the hostname. If your provider documents a stricter policy, set smtp_tls_security_level = verify and add smtp_tls_verify_cert_match = hostname, to protect against an attacker pretending to be the relay.
Create the credentials file. The format is [host]:port username:password, and the host text must match relayhost exactly, brackets included.
postmap builds the indexed sasl_passwd.db file Postfix reads. Rerun it every time you change the text file. The file holds a secret, so keep it readable by root only, and remove the plain-text copy if your policy forbids keeping one. Rotate the credentials if you ever copy the file into a ticket or a repository.
Now tell Postfix to authenticate with these credentials.
Install the SASL client plugins if Postfix reports an unsupported mechanism.
On RHEL-family systems the plugin package is cyrus-sasl-plain. Note the difference between smtp_ and smtpd_ settings: the smtp_ family controls Postfix as a client sending mail, which is what a relay needs, and smtpd_ controls it as a server receiving mail.
By default relayhost applies to every destination. Sometimes you want only certain mail to use it, for example one sender domain through an ESP. Use sender_dependent_relayhost_maps.
For a per-destination rule, use a transport map instead, for example sending only mail for example.net through a specific relay. Keep a simple default until you need these rules.
Verify the configuration, send a message and read the log.
relay=smtp.provider.example[...]:587 shows the message went through the smarthost, and status=sent means the relay accepted it. Typical failures are:
SASL authentication failed: wrong username or password, or the host in sasl_passwd does not match relayhost exactly.no mechanism available: install libsasl2-modules.Connection timed out: the port is blocked or wrong. Try 587, 2587 or 465 as your provider documents.Relay access denied or a sender rejection: the provider has not verified your sending domain or address.certificate verification failed: the CA bundle path is wrong.Check the queue with postqueue -p, and flush it with postqueue -f after a fix. Read the full journal on systems without /var/log/mail.log using sudo journalctl -u postfix.
Yes. The receiving servers evaluate your domain, so publish SPF that includes the relay and sign messages with DKIM, either with your own key or as the provider instructs.
Use 587 with STARTTLS unless the provider says otherwise. Port 465 is implicit TLS, and many providers also offer 2587 or 25 as alternatives. Avoid unencrypted connections.
Usually the key in sasl_passwd does not match relayhost, the .db file was not rebuilt with postmap, or the credentials are wrong. Brackets and the port must be identical in both places.
Yes. Use sender_dependent_relayhost_maps with smtp_sender_dependent_authentication = yes, or a transport map for a specific destination.
Set relayhost = [host]:587, require TLS with smtp_tls_security_level = encrypt, store credentials in sasl_passwd with chmod 600 and postmap, and enable smtp_sasl_auth_enable. Make sure the SASL plugin package is installed, test with a real message and confirm relay= and status=sent in the log. Keep SPF and DKIM correct, because the receiver still judges your domain.