Postfix Configure Multiple ISP Client SMTP Authentication

How do I support multiple ISP accounts (smarthost) in the Postfix SMTP client for relaying email? For example:

[a] must be relay via
[b] must be relay via
[c] must relay all my default email via

Only Postfix version v2.3+ supports multiple ISP accounts via sender-dependent override for the global relayhost parameter settings. Open your file:
# vi /etc/postfix/
Add or modify the settings as follows:

smtp_sender_dependent_authentication = yes
sender_dependent_relayhost_maps = hash:/etc/postfix/relayhost_map
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/passwd
relayhost = []:submission

Create /etc/postfix/relayhost_map file:
# vi /etc/postfix/relayhost_map
Append configuration as follows (please note that default is not included) :

# Per-sender provider		[]		[]

Create update /etc/postfix/passwd file as follows:

# Per-sender authentication
# Login for the default relayhost
[]	defaultUsername:defaultPassword

Save and close the file. Restart Postfix:
# postmap hash:/etc/postfix/passwd
# postmap hash:/etc/postfix/relayhost_map
# /etc/init.d/postfix reload


  • smtp_sender_dependent_authentication = yes : Enable sender-dependent authentication in the Postfix SMTP client; this is available only with SASL authentication.
  • sender_dependent_relayhost_maps = hash:/etc/postfix/sender_relay : A sender-dependent override for the global relayhost parameter setting. The tables are searched by the envelope sender address and @domain. A lookup result of DUNNO terminates the search without overriding the global relayhost parameter setting.
  • smtp_sasl_auth_enable = yes : Enable SASL authentication in the Postfix SMTP client. By default, the Postfix SMTP client uses no authentication.
  • smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd : SMTP client lookup tables with one username:password entry per remote hostname or domain, or sender address when sender-dependent authentication is enabled.
  • relayhost = []:submission : Setup default relay host.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 10 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
10 comments… add one
  • Sureshkumar Mar 18, 2009 @ 13:38

    Previous I was tried this concept but it was not working
    My scenarios adding multiple users with SMTP auth
    With username and passwd
    Am waiting for your reply.please scrap me or mail me
    this is my email id :

  • Sachin Sep 4, 2009 @ 18:50

    Is this also supported on sendmail?

  • Coschuetzer Oct 11, 2009 @ 23:40

    At first, thanks aslot for making this (almost) clear.

    What I don’t understand is: If …
    “[a] must be relay via
    [b] must be relay via”
    (so there is only user1 involved)

    … then why is this line in /etc/postfix/passwd ?

    Where does user2 coming from all the sudden?!

    Shouldn’t it be like this

    or do you just want to show, that the username on the “real” has not necessarily to correspondent with the “local” user1?

    Thanks for answering,

  • Wolfgang muller Nov 3, 2009 @ 17:15

    Global internet providers aim is to provide access that is effortless to utilize. They provide access that is as fast as you absolutely need it to be, and will work with the system you have.

  • David Perez Feb 5, 2013 @ 8:04

    This configuration works well for the relay of all emails in each domain. My question now is whether there is a Postfix configuration

    allowing the relay emails sent only to ‘’ for each domain. That would solve my problem, because the only emails I am having

    reception problems are with ‘’, others are working properly and I can send to my VPS server.

  • Tomas Aug 16, 2013 @ 14:27

    But, how to use a variable in /etc/postfix/passwd???
    I want postfix to authenticate with my ISP using the sender email addres as login and a fixed password. For example

    But I don’t want to write thousands of users. I want something like:
    * $sender_address:alwayssamepass

    Do you understand mem?

    • Fabio Nov 3, 2016 @ 17:35

      Did you figure it out, on how to avoid writing thousands of users?

  • Mikko Ohtamaa May 6, 2015 @ 12:30

    Thank you, excellent guide!

    I had the same issue that one website on a shared host had to use SMTP server. I was about to cry when reading the official Postfix documentation – it would take forever to process all the information there. With this guide I was able to solve the problem in a matter of an hour.

    • Fabio Nov 3, 2016 @ 18:00

      Do you know for what is this? if each user as his own provider and password?

      # Login for the default relayhost
      [] defaultUsername:defaultPassword

  • Fabio Nov 3, 2016 @ 17:40

    What do you mean with? for what if each user as his own smtp connection?

    ‘Login for the default relayhost’

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum