7

I'm running multiple websites on a single server. I'm using sendgrid to send my email.

Right now, I have postfix relay all outgoing mail to a single sendgrid account, using smtp_sasl for authentication.

I need to be able to send each domain's email to a different sendgrid account. So, for domain1.com, I'd want to relay to sendgrid using one account, and for domain2.com, I'd need postfix to use a different account to authenticate.

8

It's a shame that this one went for so long without a correct answer. And for that matter it's a shame it's not a dealt with by sendgrid's own documentation. The required directives are dealt with succinctly at http://www.postfix.org/SASL_README.html#client_sasl_sender, which I'll quote here, with some sendgrid specific modifcation:

/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 = my.default.relay.com

/etc/postfix/sasl_passwd:
    # Per-sender authentication; see also /etc/postfix/sender_relay.
    @domain1.example.com               username1:password1
    @domain2.example.com               username2:password2
    # Login information for the default relayhost.
    [my.default.relay.com]              username:password
    # Alternative form:
    # [mail.isp.example]:submission username:password

/etc/postfix/sender_relay:
    # Per-sender provider; see also /etc/postfix/sasl_passwd.
    @domain1.example.com               [sendgrid.net]:submission
    @domain2.example.com               [sendgrid.net]:submission

A few notes here though.

  1. The above switches on the SMTP Envelope From address, not the one in the MIME Header.
  2. Getting postfix to send mail in different directions on the basis of MIME Header checks is more difficult. I'm sure it's possible somehow, but postfix is not designed for this.
  3. DKIM Doesn't care whether either the SMTP Envelope from address orthe MIME Header From address match the domain used for the DKIM signing. It may be that the spam policies of some receiving servers do care. (More info much appreciated here).
  4. Because of 1. and 3., you quite possibly don't need to send to separate sendgrid sub-accounts at all.
  • This what what I've been doing for the past couple years, has worked great! – Joe Van Dyk Jun 18 '13 at 22:14
  • 1
    @JoeVanDyk your posted that comment 2 years after the question and said you've been doing this for a couple of years.. that implies you did it even before you asked the question, So why ask? – barlop Jun 13 '16 at 7:43
  • I found the answer a while after posting the question.. and forgot to come back to update. – Joe Van Dyk Oct 25 '16 at 20:19
0

sender_dependent_relayhost_maps and sender_dependent_default_transport_maps are your friends.

  • Hm, I'm still a little confused. I don't need to change the host, just the username and passwords. – Joe Van Dyk Jun 13 '11 at 20:55

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.