Mailing List Archive

Select a router per recipient on incoming messages
Hi there,

I apologise if this has been handled before. I wasn’t sure what a quick path in the FAQ would be to the answer for this.

I have a domain for which different local_parts need to be delivered to different SMTP servers.
The decision depends on whether "host-a" accepts the local_part, and otherwise it needs to be our local SMTP server.

I created these relevant config snippets for it:
(I did not paste the entire config file, just the parts relevant to my question)

```
local_domains = mydomain.tld

begin acl
acl_smtp_rcpt:
accept domains = +local_domains
verify = recipient/callout
set acl_m_hosta = "ok"

accept domains = +local_domains
message = $acl_verify_message
verify = recipient/defer_ok

deny message = relay not permitted

begin routers
hosta_verify_router:
driver = manualroute
domains = +local_domains
transport = internal_smtp
route_list = +local_domains mx.hosta.com
verify_only = true

# Relay to the GMail MX for gmail_domains
hosta_inbound_relay:
driver = manualroute
domains = +local_domains
condition = ${if eq {$acl_m_hosta} {"ok"}}
transport = internal_smtp
route_list = +local_domains mx.hosta.com <http://mx.hosta.com/>

route:
driver = manualroute
domains = +local_domains
transport = internal_smtp
route_list = +local_domains my-mx.mydomain.tld

begin transports
internal_smtp:
driver = smtp
```

This works great, as long as you have one recipient per connection.

But, when I tested what happened with 2 “RCPT TO” commands in a single connection, one for host-a, and one for local, I found out the contents of the acl_m_hosta is persistent between “RCPT TO” calls.

Digging a bit further into this I found out that the router finds the variable in a state where the last verify left it, and all addresses would be handled by the same router.

My question is this:
Is there an easy way to decide per recipient which router will be used, based on the results of a callout/verify?
Or is there a different way to establish the same result?

Thank you so much in advance,

Marco van Tol

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Select a router per recipient on incoming messages [ In reply to ]
Hi Again,

I found something that works. So now all that’s left is that I wonder if any of you would have a more readable version.

I will type what I changed to make it work inline below.


Op 20 mrt 2024, om 14:36 heeft Marco van Tol <mvantol@ripe.net> het volgende geschreven:
>
> Hi there,
>
> I apologise if this has been handled before. I wasn’t sure what a quick path in the FAQ would be to the answer for this.
>
> I have a domain for which different local_parts need to be delivered to different SMTP servers.
> The decision depends on whether "host-a" accepts the local_part, and otherwise it needs to be our local SMTP server.
>
> I created these relevant config snippets for it:
> (I did not paste the entire config file, just the parts relevant to my question)
>
> ```
> local_domains = mydomain.tld
>
> begin acl
> acl_smtp_rcpt:
> accept domains = +local_domains
> verify = recipient/callout
> set acl_m_hosta = "ok"

This I changed to:
set acl_m_hosta = $acl_m_hosta ${tr{$local_part}{=}{_}}@$domain=hosta

>
> accept domains = +local_domains
> message = $acl_verify_message
> verify = recipient/defer_ok
>
> deny message = relay not permitted
>
> begin routers
> hosta_verify_router:
> driver = manualroute
> domains = +local_domains
> transport = internal_smtp
> route_list = +local_domains mx.hosta.com
> verify_only = true
>
> # Relay to the GMail MX for gmail_domains
> hosta_inbound_relay:
> driver = manualroute
> domains = +local_domains
> condition = ${if eq {$acl_m_hosta} {"ok"}}

This I changed to:
condition = ${if eq {${extract {${tr{$local_part}{=}{_}}@$domain} {$acl_m_hosta}}} {hosta}}

> transport = internal_smtp
> route_list = +local_domains mx.hosta.com <http://mx.hosta.com/>
>
> route:
> driver = manualroute
> domains = +local_domains
> transport = internal_smtp
> route_list = +local_domains my-mx.mydomain.tld
>
> begin transports
> internal_smtp:
> driver = smtp
> ```

Thanks!

Marco van Tol


--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Select a router per recipient on incoming messages [ In reply to ]
On Wed, 20 Mar 2024, Marco van Tol via Exim-users wrote:

> Hi there,
>
> I apologise if this has been handled before. I wasn’t sure what a quick path in the FAQ would be to the answer for this.
>
> I have a domain for which different local_parts need to be delivered to different SMTP servers.
> The decision depends on whether "host-a" accepts the local_part, and otherwise it needs to be our local SMTP server.
>
>
> This works great, as long as you have one recipient per connection.
>
> But, when I tested what happened with 2 “RCPT TO” commands in a single connection, one for host-a, and one for local, I found out the contents of the acl_m_hosta is persistent between “RCPT TO” calls.
>
> Digging a bit further into this I found out that the router finds the variable in a state where the last verify left it, and all addresses would be handled by the same router.
>
> My question is this:
> Is there an easy way to decide per recipient which router will be used, based on the results of a callout/verify?
> Or is there a different way to establish the same result?

You are not using routers the way they are intended.

The idea is that *for each* address, each router is tried in turn until
one of them accepts the message, or specifies that it should be bounced.
See the Exim Spec, section 3.8 - Processing an address for delivery.

That should get you most of what you need.

--
Andrew C. Aitchison Kendal, UK
andrew@aitchison.me.uk

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Select a router per recipient on incoming messages [ In reply to ]
On 20/03/2024 13:36, Marco van Tol via Exim-users wrote:
> Is there an easy way to decide per recipient which router will be used, based on the results of a callout/verify?

That's not the simplest way of doing what you want.

> Or is there a different way to establish the same result?

Just have the router chain decide what to do for routing; no ACL involvement.
--
Cheers,
Jeremy


--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Select a router per recipient on incoming messages [ In reply to ]
Op 20 mrt 2024, om 23:32 heeft Andrew C Aitchison <andrew@aitchison.me.uk> het volgende geschreven:
> On Wed, 20 Mar 2024, Marco van Tol via Exim-users wrote:
>
>> Hi there,
>>
>> I apologise if this has been handled before. I wasn’t sure what a quick path in the FAQ would be to the answer for this.
>>
>> I have a domain for which different local_parts need to be delivered to different SMTP servers.
>> The decision depends on whether "host-a" accepts the local_part, and otherwise it needs to be our local SMTP server.
>>
>>
>> This works great, as long as you have one recipient per connection.
>>
>> But, when I tested what happened with 2 “RCPT TO” commands in a single connection, one for host-a, and one for local, I found out the contents of the acl_m_hosta is persistent between “RCPT TO” calls.
>>
>> Digging a bit further into this I found out that the router finds the variable in a state where the last verify left it, and all addresses would be handled by the same router.
>>
>> My question is this:
>> Is there an easy way to decide per recipient which router will be used, based on the results of a callout/verify?
>> Or is there a different way to establish the same result?
>
> You are not using routers the way they are intended.
>
> The idea is that *for each* address, each router is tried in turn until
> one of them accepts the message, or specifies that it should be bounced.
> See the Exim Spec, section 3.8 - Processing an address for delivery.
>
> That should get you most of what you need.

Hi, thank you for your reply, and also thanks to Jeremy who wrote more-or-less the same thing.

I have tried to find a routers config that will do this:
- try to deliver an address over smtp
- if the returned error is permanent, try the next router

This is what I would need, unless I’m overlooking something.

From what I read fallback_hosts will only try the next router on temporary failures.

I only need to try delivery to an alternative host/router if the current host/router returns a permanent error.

I looked at the options for the smtp transport, the generic routing options and the manualroute routing options, but from the documentation it doesn’t click with me that this is possible. Is it?

Sorry if I overlooked something super simple.

Thanks in advance,

Marco van Tol



--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Select a router per recipient on incoming messages [ In reply to ]
On 21/03/2024 14:33, Marco van Tol via Exim-users wrote:
> I have tried to find a routers config that will do this:
> - try to deliver an address over smtp
> - if the returned error is permanent, try the next router

> I looked at the options for the smtp transport, the generic routing options and the manualroute routing options, but from the documentation it doesn’t click with me that this is possible. Is it?

Not really, no. The first applicable router should be configured to find *the*
destination host (or set of hosts) that is/are qualified to handle the message. Inn this case it
has returned a definitive result, which is that the destination ADMD is refusing
to accept that message, and will continue to do so indefinitely.

You are supposed to abide by that.

--
Cheers,
Jeremy


--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Select a router per recipient on incoming messages [ In reply to ]
Op 21 mrt 2024, om 17:55 heeft Jeremy Harris via Exim-users <exim-users@lists.exim.org> het volgende geschreven:
>
> On 21/03/2024 14:33, Marco van Tol via Exim-users wrote:
>> I have tried to find a routers config that will do this:
>> - try to deliver an address over smtp
>> - if the returned error is permanent, try the next router
>
>> I looked at the options for the smtp transport, the generic routing options and the manualroute routing options, but from the documentation it doesn’t click with me that this is possible. Is it?
>
> Not really, no. The first applicable router should be configured to find *the*
> destination host (or set of hosts) that is/are qualified to handle the message. Inn this case it
> has returned a definitive result, which is that the destination ADMD is refusing
> to accept that message, and will continue to do so indefinitely.
>
> You are supposed to abide by that.

Makes sense, thanks so much for reading my questions and sending responses.

Marco van Tol


--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/