[Pkg-exim4-users] How to choose a smarthost based on From: address in Exim4

Ian Kelling iank at fsf.org
Mon Mar 20 15:09:01 GMT 2023


Faheem Mitha via Pkg-exim4-users <pkg-exim4-users at alioth-lists.debian.net> writes:

> I have been trying, off and on, for some months, to figure out a way,
> when sending an email via Exim4, to select the smarthost based on the
> From address (the sender's address). I would prefer to use Debian's
> configuration system, which is based in part on the variables in
> `update-exim4.conf.conf`.
>
> This seems to me like it should be easy to do, but apparently not.
>
> This question has come up in various forums. What most of the answers
> have in common is their complexity, and lots of boiler
> plate. Additionally, none of the answers writers took any time to
> explain their answers.
>
> However, I did find one answer that looked relatively simple. This was a
> 2022 post on the Debian user mailing list by Marc Auslander with the
> Subject: "Re: exim4 smarthost selection based on sender", namely
> https://lists.debian.org/debian-user/2022/11/msg00881.html.
>
> Auslander's solution is
>
> dc_smarthost='"${if match{${lc:$header_from:}}{.*xxx.org}{smtp.xxx.net::587}{${if match{${lc:$header_subject:}}{SSS}{mail.SSS.net}{smtp.googlemail.com::587}}}}"'
>
> This uses syntax as described in
> https://www.exim.org/exim-html-current/doc/html/spec_html/ch-string_expansions.html
> in Section 5: Expansion items, namely
>
>     ${if <condition> {<string1>}{<string2>}}
>
> and Section 7: Expansion conditions, namely
>
>     match {<string1>}{<string2>}
>
> Alternatively, if you have the official Exim book, "The Exim SMTP Mail
> Server" (my version is "Official Guide for Release 4", First Edition,
> published 2003), this syntax is discussed in Section 17.7, with
> `match` covered in Section 17.7.3.
>
> As described in a followup email by Gregory Seidman
> (https://lists.debian.org/debian-user/2022/11/msg00884.html), in terms
> of pseudocode this amounts to
>
> if the from header matches .*xxx.org then
>   use smtp.xxx.net
> else if the subject matches SSS then
>   use mail.SSS.net
> else
>   use smtp.googlemail.com
>
> The position of the Debian Exim team seems to be that Exim is not
> designed to suppport such a configuration. See for example the
> discussion in
> https://alioth-lists.debian.net/pipermail/pkg-exim4-users/2015-May/thread.html
>
> To quote Marc Haber from the second message in that thread
> (https://alioth-lists.debian.net/pipermail/pkg-exim4-users/2015-May/002237.html):
>
>> I only have the short version: exim is not really geared for this
>> leaf system typical use case. This especially applies to freemailers
>> which in turn are not really geared to accept messages from software
>> other than MUAs.
>
>> There are numerous solutions for this issue. I believe that some of
>>  them are in the list archives. None of them, however, caters for
>>  all corner cases that might arise from the challenge.
>
> So, given that experts in Exim are presumably on this mailing list,
> can you tell me what problems there are with the solution above, if
> any? If this solution doesn't have any glaring issues, I could post
> the solution online, for example on [How to choose a smarthost based
> on From: address in exim4 on Debian](https://serverfault.com/q/747568).
>

I don't know what Marc Haber is talking about, but I don't think there
are any issues. I have my workstation's exim setup to go to various
smarthost based on the rcpt from address. That has worked well for
years for me. Doing it that way would handle bounces, using the from
header wouldn't. here is an example:


dd of=/etc/exim4/conf.d/router/188_exim4-config_smarthost <<'EOF'
# ian: copied from /etc/exim4/conf.d/router/200_exim4-config_primary, and added senders = and
# replaced DCsmarthost with hostname
fsfsmarthost:
  debug_print = "R: smarthost for $local_part@$domain"
  driver = manualroute
  domains = ! +local_domains
  senders = *@fsf.org
  transport = remote_smtp_smarthost
  route_list = * mail.fsf.org::587 byname
  host_find_failed = ignore
  same_domain_copy_routing = yes
  no_more

posteosmarthost:
  debug_print = "R: smarthost for $local_part@$domain"
  driver = manualroute
  domains = ! +local_domains
  senders = *@posteo.net
  transport = remote_smtp_smarthost
  route_list = * posteo.de::587 byname
  host_find_failed = ignore
  same_domain_copy_routing = yes
  no_more
EOF




More information about the Pkg-exim4-users mailing list