Postfix: SMTP forwarding based on sender 
Postfix: sender-dependent SASL authentication — relay to multiple SMTP hosts, or relay to the same host but authenticate as different users (e.g., two Gmail accounts)

I would like to send mail from two different Gmail accounts using Postfix.

As a concrete example, here's how to set up two Gmail accounts (only relevant sections of the config files are listed below):

/etc/postfix/main.cf:
# sender-dependent sasl authentication
smtp_sender_dependent_authentication = yes
sender_dependent_relayhost_maps = hash:/etc/postfix/sender_relay

# default relayhost setting
relayhost = [smtp.gmail.com]:587

# smtp authentication settings
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = plain
smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt
smtp_use_tls = yes
smtp_tls_security_level = encrypt

/etc/postfix/sasl_passwd:
# per-sender authentication
account1[@]gmail.com account1[@]gmail.com:passwd1
account2[@]gmail.com account2[@]gmail.com:passwd2

# default relayhost
[smtp.gmail.com]:587 default_account[@]gmail.com:default_passwd

/etc/postfix/sender_relay:
account1[@]gmail.com [smtp.gmail.com]:587
account2[@]gmail.com [smtp.gmail.com]:587


Create maps:
postmap sasl_passwd sender_relay


Restart postfix and test:

To send an email from account1[@]gmail.com, use sendmail with the -f sender option (set the envelope sender address):

sendmail -f account1[@]gmail.com -t <<EOF
To: barney[@]example.net
Subject: Hey, I successfully configured Postfix with sender-dependent SASL authentication!
Content-type: text/html

<b>Isn't this awesome?</b>
EOF


as of 2/2015:
https://gist.github.com/zmwangx/2c56aa32be68daf48c2f

Comments
Comments are not available for this entry.
2024 By Angel Cool