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] [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

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]

# 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

# 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: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.