Mailing List Archive

Smarthost condition by h_From header variable
Dear Users,

I am trying to create a smarthost manualroute route depending on From:
header. Here is my router:

smarthost:
driver = manualroute
domains = ! +local_domains
condition = ${if eq{${domain:$h_From:}}{domain.com}}
transport = remote_smtp
route_data = XXX.XXX.XXX.XXX
no_more

What have I done wrong? Why is $h_From: variable empty in manualroute
driver?

How to make a correct condition to check the From header?

Thanks in advance,

J?nos



--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Smarthost condition by h_From header variable [ In reply to ]
Hi,

Gallai János via Exim-users <exim-users@exim.org> (Do 21 Jun 2018 08:34:39 CEST):
> Dear Users,
>
> I am trying to create a smarthost manualroute route depending on From:
> header. Here is my router:
>
> smarthost:
> driver = manualroute
> domains = ! +local_domains
> condition = ${if eq{${domain:$h_From:}}{domain.com}}
> transport = remote_smtp
> route_data = XXX.XXX.XXX.XXX
> no_more
>
> What have I done wrong? Why is $h_From: variable empty in manualroute
> driver?
>
> How to make a correct condition to check the From header?

Depends on when the router is run.

If you call the router implicitly from the ACL (require verify =
recipient, … or similiar) there is hot header yet.

If you test the router using `exim -bt …` it won't work, for the same
reason, as there is no header yet.

Better router testing you can do using Exim's -N option and a
handcrafted message.

If the message is received already, the header is set and the router
should work.

Best regards from Dresden/Germany
Viele Grüße aus Dresden
Heiko Schlittermann
--
SCHLITTERMANN.de ---------------------------- internet & unix support -
Heiko Schlittermann, Dipl.-Ing. (TU) - {fon,fax}: +49.351.802998{1,3} -
gnupg encrypted messages are welcome --------------- key ID: F69376CE -
! key id 7CBF764A and 972EAC9F are revoked since 2015-01 ------------ -
Re: Smarthost condition by h_From header variable [ In reply to ]
On 06/21/2018 07:34 AM, Gallai J?nos via Exim-users wrote:
> I am trying to create a smarthost manualroute route depending on From:
> header. Here is my router:

1) It's relatively unlikely you really do want to use the
From: header. More likely would be the _envelope_ sender
address. If you don't understand the distinction, please read
up on general email concepts.

>
> smarthost:
> ? driver = manualroute
> ? domains = ! +local_domains
> ? condition = ${if eq{${domain:$h_From:}}{domain.com}}
> ? transport = remote_smtp
> ? route_data = XXX.XXX.XXX.XXX
> ? no_more
>
> What have I done wrong? Why is $h_From: variable empty in manualroute
> driver?

2) If you really do want to deal with a header, you need to
be aware that it contains more than a local-part and a
domain. See the "address" expansion operator.
However, I am not convinced that you do.

3) You've not demonstrated that $h_From: was empty.
--
Cheers,
Jeremy

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Smarthost condition by h_From header variable [ In reply to ]
Hello,

Others on the list have pointed out that you might not actually be wanting
to use the value of the $h_From variable but instead the domain of the
envelope.

If you do decide to use the domain of the From header itself you might want
to do some additional testing, or write your test defensively… The
*Specification* does not state in its description of the
"${domain:<string>}" string expansion that the letters in its value are
converted to lower case. Therefore I'd be minded either to test the
expression when the From header contains a domain name in capital or mixed
case letters, or write the expression defensively and use "eqi" to compare
the two strings instead of "eq".

(In contrast the *Specification* does explicitly state that when Exim
assigns the value to the "$domain" variable it is first converted to lower
case.)

Cheers,
Mike B-)

On Thu, 21 Jun 2018 at 12:11, Gallai János via Exim-users <
exim-users@exim.org> wrote:

> Dear Users,
>
> I am trying to create a smarthost manualroute route depending on From:
> header. Here is my router:
>
> smarthost:
> driver = manualroute
> domains = ! +local_domains
> condition = ${if eq{${domain:$h_From:}}{domain.com}}
> transport = remote_smtp
> route_data = XXX.XXX.XXX.XXX
> no_more
>
> What have I done wrong? Why is $h_From: variable empty in manualroute
> driver?
>
> How to make a correct condition to check the From header?
>
> Thanks in advance,
>
> János
>
>
>
> --
> ## List details at https://lists.exim.org/mailman/listinfo/exim-users
> ## Exim details at http://www.exim.org/
> ## Please use the Wiki with this list - http://wiki.exim.org/
>


--
Systems Administrator & Change Manager
IT Services, University of York, Heslington, York YO10 5DD, UK
Tel: +44-(0)1904-323811

Web: www.york.ac.uk/it-services
Disclaimer: www.york.ac.uk/docs/disclaimer/email.htm
--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Smarthost condition by h_From header variable [ In reply to ]
Dear Heiko,

I've tried envelope_sender but Exim says unknow variable.

The goal is: We would like to use a separate smarthost for specified
domains on real sender ( envelope_sender ) which is in the From: header.

For example: many users use webmail where the sender is www@domain.com,
the real sender is user@otherdomain.com. There is no problem with MUAs
but webmail users always send mail with sender www@domain.com so the
real sender is in the From: header. I need to get this address somehow.

If I try this:

smarthost:
driver = manualroute
debug_print = Domain: From: ${local_part}@${domain}, Sender: $header_From
domains = ! pgsql;SELECT nev FROM domain WHERE nev =
'${quote_pgsql:$domain}' AND local = 1
condition = ${if match_domain{${domain:$h_From:}}{domain.com}{yes}{no}}
transport = remote_smtp
route_data = XXX.XXX.XXX.XXX
no_verify
no_more

It seems it works well. When $h_From is 'domain.com' it send to
smarthost if not it doesn't sends to smarthost but uses direct smtp.

But with an SQL it always calls smarthost router:

smarthost:
driver = manualroute
debug_print = Domain: From: ${local_part}@${domain}, Sender: $header_From
domains = ! pgsql;SELECT nev FROM domain WHERE nev =
'${quote_pgsql:$domain}' AND local = 1
condition = ${if match_domain{${domain:$h_From:}}{lookup pgsql{SELECT
nev FROM domain WHERE nev = '${domain:$h_From:}' AND relay = 1}{yes}{no}}}
transport = remote_smtp
route_data = XXX.XXX.XXX.XXX
no_verify
no_more

If I run the SQL-query manually it works fine: gives me back that expected.

I understand that I do something wrong but what?

Thanks,

J?nos





2018-06-21 13:27 keltez?ssel, Heiko Schlittermann via Exim-users ?rta:
> Hi,
>
> Gallai J?nos via Exim-users <exim-users@exim.org> (Do 21 Jun 2018 08:34:39 CEST):
>> Dear Users,
>>
>> I am trying to create a smarthost manualroute route depending on From:
>> header. Here is my router:
>>
>> smarthost:
>> driver = manualroute
>> domains = ! +local_domains
>> condition = ${if eq{${domain:$h_From:}}{domain.com}}
>> transport = remote_smtp
>> route_data = XXX.XXX.XXX.XXX
>> no_more
>>
>> What have I done wrong? Why is $h_From: variable empty in manualroute
>> driver?
>>
>> How to make a correct condition to check the From header?
> Depends on when the router is run.
>
> If you call the router implicitly from the ACL (require verify =
> recipient, ? or similiar) there is hot header yet.
>
> If you test the router using `exim -bt ?` it won't work, for the same
> reason, as there is no header yet.
>
> Better router testing you can do using Exim's -N option and a
> handcrafted message.
>
> If the message is received already, the header is set and the router
> should work.
>
> Best regards from Dresden/Germany
> Viele Gr??e aus Dresden
> Heiko Schlittermann
>
>

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Smarthost condition by h_From header variable [ In reply to ]
Gallai János via Exim-users <exim-users@exim.org> (Fr 22 Jun 2018 11:36:16 CEST):
> Dear Heiko,
>
> I've tried envelope_sender but Exim says unknow variable.
>
> The goal is: We would like to use a separate smarthost for specified domains
> on real sender ( envelope_sender ) which is in the From: header.

The envelope sender doesn't have to match the From: header, as From: may
contain multiple addresses. If so, Sender: should exist and contain only
one address.

> For example: many users use webmail where the sender is www@domain.com, the
> real sender is user@otherdomain.com. There is no problem with MUAs but

Yes, I'd consider this as a misconfiguration of the webmailer.
Most people do not care, because the do not know anything about envelope
senders. The same is true for MUAs. And for replies normal MUAs use the
From: header (or Reply-to:, if available).

The envelope sender is used for bounces. And even webmail users should
get the bounces they triggger. But with having www@domain.com as
envelope sender, there is no chance.

So - you should try hard to set the envelope sender to the address of
the "responsive" originating user.

> webmail users always send mail with sender www@domain.com so the real sender
> is in the From: header. I need to get this address somehow.

The variables you need are

$sender_address
$sender_address_local_part
$sender_address_domain


> smarthost:
> driver = manualroute
> debug_print = Domain: From: ${local_part}@${domain}, Sender: $header_From
> domains = ! pgsql;SELECT nev FROM domain WHERE nev =
> '${quote_pgsql:$domain}' AND local = 1
> condition = ${if match_domain{${domain:$h_From:}}{lookup pgsql{SELECT nev
> FROM domain WHERE nev = '${domain:$h_From:}' AND relay = 1}{yes}{no}}}
> transport = remote_smtp
> route_data = XXX.XXX.XXX.XXX
> no_verify
> no_more
>
> If I run the SQL-query manually it works fine: gives me back that expected.
> I understand that I do something wrong but what?

How to you test your setup?
--
Heiko