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

Faheem Mitha faheem at faheem.info
Sun Apr 2 07:46:13 BST 2023


On Sun, 19 Mar 2023, Faheem Mitha wrote:

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

[snip]

> 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 is a followup to my email to the Pkg-exim4-users dated 19th March 
2023. I asked to hear about problems with the solution by Marc Auslander, 
but nobody told me of any.

I tried slightly modifying the solution by Marc Auslander as described
in my earlier email. But it gives me a mysterious error message.

I asked about this on Stack Overflow, but no reply yet. The URL for
that question is https://stackoverflow.com/q/75891539/350713

I'll repeat a shortened version of this below.

My modified version of the solution by Auslander is

     dc_smarthost='"${if match{${lc:$header_from:}}{.*gmail.com}{smtp.gmail.com::587}{${if match{${lc:$header_from:}}{.*mydomain|.*mailbox.org}{smtp.mailbox.org::587}{secure-email-32.luxsci.com::587}}}}"'

This amounts to the pseudocode

     if the from header matches the regex .*gmail.com
         then
             use smtp.gmail.com::587
     else if the from header matches .*mydomain|.*mailbox.org
         then
             use smtp.mailbox.org::587
     else # default if nothing else matches
             use secure-email-32.luxsci.com::587

This seems like a simple modification of Auslander, but I get the
error

     Mar 30 01:59:54 orwell exim4[3626569]: sed: -e expression #1, char 
861: unknown option to `s'

I have no idea how to debug this. An explanation of the error would be
appreciated. A version that works would be even more appreciated.

Regards, Faheem Mitha



More information about the Pkg-exim4-users mailing list