# Configure postfix to use a relay server

Tags: postfix email

Add the following to /etc/postfix/main.cf:

smtp_sasl_auth_enable = yes
smtp_tls_security_level = encrypt
smtp_sasl_tls_security_options = noanonymous
relayhost = [mail.isp.example]:port


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


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/main.cf:

sender_dependent_relayhost_maps = hash:/etc/postfix/relayhosts


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

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


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

Finally, generate the database file with

# postmap /etc/postfix/relayhosts