Configure postfix to use a relay server

Tags: postfix email

Add the following to /etc/postfix/

smtp_sasl_auth_enable = yes
smtp_tls_security_level = encrypt
smtp_sasl_tls_security_options = noanonymous
relayhost = [mail.isp.example]:port
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

In /etc/postfix/sasl_passwd add:

[mail.isp.example]:port username:password

SMTP relay and username and password with the username and password used to authenticate with the relay. The brackets around the host name tell Postfix to disable MX lookups and to use the domain name exactly as entered. These can be entered literally, they do not denote optional values). removed if that is not desirable. (Note that the [ and ] characters should be replacing mail.isp.example and port with the domain name and port of the

Then, run

# postmap /etc/postfix/sasl_passwd
# postfix reload

If the postfix server is not already running, use postfix start instead of postfix reload.

Using sender dependent relays

To use sender dependent relays, add the following to /etc/postfix/

sender_dependent_relayhost_maps = hash:/etc/postfix/relayhosts

Create /etc/postfix/relayhosts with the following contents:

@domain [mail.isp.example]:port [mail.isp.example]:port

The key value in this file can be either a domain (@domain) or an envelope-from address (

Finally, generate the database file with

# postmap /etc/postfix/relayhosts
# postfix reload