Postfix Configure Multiple ISP Client SMTP Authentication

Posted on in Categories , , , , , , , , , , , , last updated March 13, 2009

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

[a] [email protected] must be relay via smtp.isp1.com.
[b] [email protected] must be relay via smtp.isp2.com.
[c] [email protected] must relay all my default email via smtp.mycorp.com.

Only Postfix version v2.3+ supports multiple ISP accounts via sender-dependent override for the global relayhost parameter settings. Open your main.cf file:
# vi /etc/postfix/main.cf
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 = [smtp.mycorp.com]:submission

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

# Per-sender provider
[email protected]		[smtp.isp1.com]
[email protected]		[smtp.isp2.com]

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

# Per-sender authentication
[email protected]		[email protected]:password4isp1
[email protected]		[email protected]:password4isp2
# Login for the default relayhost
[smtp.mycorp.com]	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

Where,

  • 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 = [mail.myisp.net]:submission : Setup default relay host.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

10 comment

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

    What I don’t understand is: If …
    “[a] [email protected] must be relay via smtp.isp1.com.
    [b] [email protected] must be relay via smtp.isp2.com.”
    (so there is only user1 involved)

    … then why is this line in /etc/postfix/passwd ?
    [email protected] [email protected]:password4isp2″

    Where does user2 coming from all the sudden?!

    Shouldn’t it be like this
    [email protected] [email protected]:password4isp2″

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

    Thanks for answering,
    Coschuetzer

  2. 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.

  3. 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 ‘hotmail.com’ for each domain. That would solve my problem, because the only emails I am having

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

  4. 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

    [email protected] [email protected]:alwayssamepass
    [email protected] [email protected]:alwayssamepass
    [email protected] [email protected]:alwayssamepass

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

    Do you understand mem?

  5. Thank you, excellent guide!

    I had the same issue that one website on a shared host had to use office365.com 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.

Leave a Comment