Using Postfix to relay via multiple Google Apps accounts

Solution 1:

You need to enable sender dependent authentication so that Postfix will choose the appropriate credentials based on the sender of the message being delivered. The password map should be keyed by the sender address instead of the relay host.

main.cf:

smtp_sender_dependent_authentication = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_password_maps

sasl_password_maps:

[email protected] [email protected]:password123
[email protected] [email protected]:password456

Solution 2:

Sender dependent authentication can help. There is good example in official documentation.

Postfix supports different ISP accounts for different sender addresses (version 2.3 and later). This can be useful when one person uses the same machine for work and for personal use, or when people with different ISP accounts share the same Postfix server.

To make this possible, Postfix supports per-sender SASL passwords and per-sender relay hosts. In the example below, the Postfix SMTP client will search the SASL password file by sender address before it searches that same file by destination. Likewise, the Postfix trivial-rewrite(8) daemon will search the per-sender relayhost file, and use the default relayhost setting only as a final resort.

/etc/postfix/main.cf:

smtp_sender_dependent_authentication = yes
sender_dependent_relayhost_maps = hash:/etc/postfix/sender_relay
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
relayhost = [mail.isp.example]
# Alternative form:
# relayhost = [mail.isp.example]:port

/etc/postfix/sasl_passwd:

# Per-sender authentication; see also /etc/postfix/sender_relay.
[email protected]               username1:password1
[email protected]               username2:password2
# Login information for the default relayhost.
[mail.isp.example]              username:password
# Alternative form:
# [mail.isp.example]:port username:password

/etc/postfix/sender_relay:

# Per-sender provider; see also /etc/postfix/sasl_passwd.
[email protected]               [mail.example.com]:port
[email protected]               [mail.example.net]
  • Execute the command "postmap /etc/postfix/sasl_passwd" whenever you change the sasl_passwd table.
  • Execute the command "postmap /etc/postfix/sender_relay" whenever you change the sender_relay table.