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

Faheem Mitha faheem at faheem.info
Sun Mar 19 10:56:23 GMT 2023


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

Regards, Faheem Mitha



More information about the Pkg-exim4-users mailing list