Skip to content

Setting up Sender Dependent Authentication (Sender Based Relay)

Jamen edited this page Nov 3, 2020 · 4 revisions

Use Case:

Let's say that I have 4 gmail accounts. [email protected], [email protected], [email protected] and [email protected]

My relay server is configured with an IP of 169.254.1.12.

I want mail sent by my organization to be sent through my relay as the account specified in the "From:" field of the message, and send out through [email protected] if no "From:" is specified, or it doesn't match the other 3 addresses.

Let's Start!

After a working relay server is configured, the /etc/postfix/main.cf can be modified to add in the following lines.

smtp_sender_dependent_authentication = yes
sender_dependent_relayhost_maps = hash:/etc/postfix/sender_relay

Then, the /etc/postfix/sasl_passwd file can be modified

Then edit the /etc/postfix/sender_relay

[email protected] [smtp.gmail.com]:587
[email protected] [smtp.gmail.com]:587
[email protected] [smtp.gmail.com]:587

Each of these accounts will need to be set up with oauth2 and have their information placed at /etc/tokens/[address] or /var/spool/postfix/etc/tokens/[address]

Don't forget to run postmap on the newly created files.

$ cd /etc/postfix
$ sudo postmap sasl_passwd sender_relay