5

I want to route emails with the From: .*@host1.com through smtp.server1.com and emails with the From: .*@host2.com through smtp.server2.com.

For the moment, I have smarthost configured with dpkg-reconfigure exim4-config so that update-exim4.conf.conf contains the line dc_smarthost='smtp.server1.com::587'. That is, everything routes through smtp.server1.com.

I tried adding another router just before the definition of smarthost: in the config file, setting senders = .*@host2.com

smarthost_server2:
  debug_print = "R: smarthost_server2 for $local_part@$domain"
  driver = manualroute
  domains = ! +local_domains
  transport = remote_smtp_smarthost
  senders = .*@host2.com
  route_list = * smtp.server2.com byname
  host_find_failed = ignore
  same_domain_copy_routing = yes
no_more

but exim still routes everyting via smtp.server1.com. Do I use the senders condition correctly?

AFAIU, this should be a rather common setup for cases when people with emails .@google.com and .@gmail.com do not want to reveal in their @gmail.com email headers the fact that they are also google employees, so the routhing should be different.

mikhailian
  • 201
  • 1
  • 7

1 Answers1

5

OK, I got it. senders is what /etc/mailname provides, not the domain part of the From:

The following works:

begin routers

smarthost1:
  driver = manualroute
  domains = ! +local_domains
  condition = ${if match_domain{${domain:$h_From:}}{domain.com}{yes}{no}}
  transport = remote_domain_com_smtp
  route_data = domain.com::587
  ignore_target_hosts = <; 0.0.0.0 ; 127.0.0.0/8 ; ::1

smarthost2:
  driver = manualroute
  domains = ! +local_domains
  condition = ${if match_domain{${domain:$h_From:}}{domain.org}{yes}{no}}
  transport = remote_domain_org_smtp
  route_data = domain.org::587
  ignore_target_hosts = <; 0.0.0.0 ; 127.0.0.0/8 ; ::1


begin transports

remote_domain_com_smtp:
  driver = smtp
  message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
  hosts_require_auth = domain.com
  headers_remove = received
  return_path = ${address:$h_from:}


remote_domain_org_smtp:
  driver = smtp
  message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
  hosts_require_auth = domain.org
  return_path = ${address:$h_from:}

where domain.com and domain.org are respectively the domains I want to choose between.

mikhailian
  • 201
  • 1
  • 7
  • Greetings from 2022. I'm trying to do the same thing as you are in this question. This is rather a belated question, but can you show your entire config file? Which is still I believe, `/etc/exim4/update-exim4.conf.conf`. Did you somehow use the Debian approach of generating this file, or did you just add some text to the existing file? – Faheem Mitha Feb 17 '22 at 19:54
  • I am still using that same config from 2016. It won't help you in its entirety, but you need a router section and a transport section for each host. Will try to update the answer now. – mikhailian Feb 18 '22 at 20:23
  • FYI, It's much simpler to do this in plain exim config, Debian config is a hell to deal with. – mikhailian Feb 18 '22 at 20:38
  • Thanks for taking the time to update. I'll take a look at it, and followup if I have questions. Why is the Debian config more difficult to deal with? – Faheem Mitha Feb 19 '22 at 09:06