Is it possible to configure SMTP authentication on Postfix with different user/pass credentials for different domains?

So, I have a MTA that relays emails from ~20 different domains. When sending emails to a specific domain, say example.com, my MTA has to authenticate. No problem, this solved the problem: http://postfix.state-of-mind.de/patrick.koetter/smtpauth/smtp_auth_mailservers.html

But, I have a different account for every sender domain. So, when mydomain1.com sends email to example.com, it uses one account. Another one for mydomain2.com -> example.com etc.

Is this achievable through Postfix?


You should read up a bit on this option: smtp_sender_dependent_authentication, with that, and two other related DB mappings, sender_dependent_relayhost_maps, and smtp_sasl_password_maps, you can create per sender password entries.

In the sender_dependent_relayhost maps, you map username@domain [smtp_host], and in the smtp_sasl_password maps, you map email user:password or domain user:password(whatever those might be). These are classic postfix lookup tables, they can be in mysql, dbm, hash, etc.

With a combination of mysql and some duplication, you could quite possibly do what you want.

You could make a table with 4 fields, email, smtp_relay, user, password, then have postfix look up the email and smtp_relay for the sender_dependent_relay_maps, then email user:password for smtp_sasl_password_maps. This would have to be populated with each email address that has to relay, each server that you relay through, and each user:password combo for the authentication.

  • 1
    Very good answer,but you could have linked the official SOHO configuration readme ;-) postfix.org/SOHO_README.html#client_sasl_sender – Stefan Förster Jan 8 '14 at 6:58
  • @StefanFörster Yeah, but I wanted to explain the slightly different logic you would have to use to solve his situation, as not only does he have multiple relays, but each from domain needs a different account to send with.. it feels a bit cheap to write look at this, but change here, here and here :) – NickW Jan 8 '14 at 9:10
  • @NickW -- thanks for the answer. Could wildcards be used? Like, *@mydomain1.com, *@mydomain2.com etc. Because there are hundreds of mail addresses and dozens of domains. Only one destination mail server. User accounts on destination servers are 1:1 for domain:account. Users need to authenticate *only when sending emails to a single exact mail server. When sending to other mail addresses, no need for authentication. – kreso Jan 8 '14 at 10:13
  • As far as I know, you should be able to use them, have a look at the pcre: maps.. postfix.org/pcre_table.5.html – NickW Jan 8 '14 at 10:25
  • This probably isn't what I'm looking for. If I'm not mistaken, sender_dependent_relayhost_maps would just say that all emails from sender@domain1.com are being relayed to smtp_host. What I'd need is, if there is mail from ANY_USER@domain1.com, being sent to smtphost.address.com, then authenticate using account domain1.com|password1. All other emails should just be relayed based on MX records. – kreso Jan 8 '14 at 10:26

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.