Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fvigotti/af301b6cae797c0342b40d2cdd5d69cc to your computer and use it in GitHub Desktop.
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)

This is a sequel to "Postfix: relay to authenticated SMTP".

I would like to send mail from two different Gmail accounts using Postfix. Here is the relevant section in the Postfix documentation: Configuring Sender-Dependent SASL authentication.

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

    # sender-dependent sasl authentication
    smtp_sender_dependent_authentication = yes
    sender_dependent_relayhost_maps = hash:/etc/postfix/sender_relay
    # default relayhost setting
    relayhost = []: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
    # per-sender authentication
    # default relayhost
/etc/postfix/sender_relay: []:587 []:587

After editing the config files (sudo su), do

chmod 600 /etc/postfix/sasl_passwd
postmap sasl_passwd sender_relay
postfix reload

And you're all set.

To send an email from, use sendmail with the -f sender option (set the envelope sender address):

sendmail -f -t <<EOF
Subject: Hey, I successfully configured Postfix with sender-dependent SASL authentication!
Content-type: text/html

<b>Isn't this awesome?</b>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment