How to route specific domains via SmartHost and rest the default method

Namhost

New member
Joined
Sep 10, 2024
Messages
3
Good day,

I have been struggling to get this to work and I am not sure if what I am doing is correct. We use SpamExperts as our filtering server. We have currently configured all sending domain names to route emails via the smarthost by having the following in place In my `/etc/exim.routers.pre.conf`:

```
smart_route_forward:
driver = manualroute
domains = ! +local_domains
ignore_target_hosts = 127.0.0.0/8
condition = ${if !eq{$original_domain}{$domain}}
condition = ${if !eq{$original_domain}{}}
condition = "${perl{check_limits}}"

transport = remote_smtp_forward_transport

route_list = * hostname::587
no_more


smart_route:
driver = manualroute
domains = ! +local_domains
ignore_target_hosts = 127.0.0.0/8
condition = "${perl{check_limits}}"

transport = remote_smtp

route_list = * hostname::587
no_more
````

And in my `/etc/exim.transports.pre.conf` I have the following:

```
spamexperts_smarthost_transport:
driver = smtp
port = 587
hosts_require_tls = hostname
```

This works 100% and is sending out emails, but as mentioned, its applying this route for ALL sending domain names. And instead, we want only specific domain names to pass via the smarthost.

So I created

`/etc/spamexperts_domains` and I list a bunch of domain names in it like so:

```
example.com
test.com
blabla.com
```

And then I updated my `/etc/exim.routers.pre.conf` to:

```
smart_route_forward:
driver = manualroute
domains = ! +local_domains
ignore_target_hosts = 127.0.0.0/8
condition = ${if match_domain{$sender_address_domain}{lsearch;/etc/spamexperts_domains}}
# Exclude null sender messages from relaying via the smarthost
condition = ${if or {{!eq{$sender_address}{}} {!eq{$sender_host_address}{}}}}
transport = remote_smtp_forward_transport
route_list = $domain hostname::587
no_more
```

and my `/etc/exim.transports.pre.conf` with:

```
spamexperts_smarthost_transport:
driver = smtp
port = 587
hosts_require_tls = hostname
interface = ${if exists {/etc/mailips}{${lookup{$sender_address_domain}lsearch*{/etc/mailips}{$value}{}}}{}}
helo_data = ${if exists {/etc/mailhelo}{${lookup{$sender_address_domain}lsearch*{/etc/mailhelo}{$value}{$primary_hostname}}}{$primary_hostname}}
headers_add = "${perl{check_mail_permissions_headers}}"
```

Now the domain names sending emails that are NOT listed in `/etc/spamexperts_domains` are perfectly sending emails out via the default intended way, which is what I expect. However, the domain names that ARE listed in `/etc/spamexperts_domains` are now bouncing with the following:

```
recpientaddress@gmail.com
host hostname [hostname public IP]
SMTP error from remote mail server after MAIL FROM:<[email protected]> SIZE=1609:
550-Verification failed for <SRS0=2ede=qi=sendingdomain.com=example@gmail.com>
550-Called: 108.177.15.27
550-Sent: RCPT TO:<SRS0=2ede=qi=sendingdomain.com=example@gmail.com>
550-Response: 550-5.1.1 The email account that you tried to reach does not exist. Please try
550-550-5.1.1 double-checking the recipient's email address for typos or
550-550-5.1.1 unnecessary spaces. For more information, go to
550-550 5.1.1 https://support.google.com/mail/?p=NoSuchUser ffacd0b85a97d-3789569a855si3111104f8f.494 - gsmtp
550 Invalid sender <srs0=2ede=qi=sendingdomain.com=example@gmail.com>
```

But I do not understand, I am sending a test email to `recpientaddress@gmail.com` from `[email protected]` but then the headers are changed oddly to some sort of forwarder, which I do not understand where it's coming from.

In any case, is what I have done above correct? I also want to reference documentation on this here:
- This is what I initially had in place: https://documentation.n-able.com/sp...vel/outgoing-filtering/exim-ip-based-auth.htm
- This is the method I want to use: https://documentation.n-able.com/sp.../outgoing-filtering/cpanel-whm-ip-auth-sd.htm

But as you can see, https://documentation.n-able.com/sp.../outgoing-filtering/cpanel-whm-ip-auth-sd.htm is related to cPanel, but I figured since both use Exim the configuration should be similar.

I would appreciate any feedback in this case.
 
I managed to get this working:

I updated my `exim.transports.pre.conf ` to:

```
smart_route_forward:
driver = manualroute
domains = ! +local_domains
ignore_target_hosts = 127.0.0.0/8
condition = ${if match_domain{$sender_address_domain}{lsearch;/etc/spamexperts_domains}}

transport = spamexperts_smarthost_transport

route_list = $domain hostname::587
no_more
```

And my `exim.transports.pre.conf` to:

```
spamexperts_smarthost_transport:
driver = smtp
port = 587
hosts_require_tls = hostname
.include_if_exists /etc/exim.dkim.conf
```

And now it seems to work as expected. However, I picked up that email forwarders configured in DA, that forward to remote recipient addresses, they do not seem to pass via the smarthost.

Is there any way this can be solved? Forwarding to local addresses is fine, but any email that goes out to a remote recipient should pass via smarthost, assuming the sending/forwarding domain name is specified in `/etc/spamexperts_domains`.
 
you forgot to add "smart_route", Currently only "smart_route_forward" show in your config.
 
I thought you could do this which makes it easier.

Create your exclude list:
/etc/spamexperts_domains

Add this to config exim:
domainlist exclude_sender_domains = lsearch;/etc/spamexperts_domains

And then add it to the router config of spamexperts like this (exim.routers.pre.conf)

senders = !*@+exclude_sender_domains

Code:
spamexperts_smarthost_router:
    driver = manualroute
    domains = ! +local_domains
    senders = !*@+exclude_sender_domains
    ignore_target_hosts = 127.0.0.0/8
    condition = "${perl{check_limits}}"
    # Exclude null sender messages from relaying via the smarthost
    condition = ${if or {{!eq{$sender_address}{}} {!eq{$sender_host_address}{}}}}
    headers_add = ${if !eq{$original_domain}{$domain}{X-Forwarded-For: $original_local_part@$original_domain}}
    headers_add = X-AuthUser: $authenticated_id
    transport = spamexperts_smarthost_transport
    route_list = $domain SMARTHOST::587
    no_more

smartexperts_smarthost_forward:
    driver = manualroute
    domains = ! +local_domains
    senders = !*@+exclude_sender_domains
    ignore_target_hosts = 127.0.0.0/8
    condition = ${if or {{!eq{$sender_address}{}} {!eq{$sender_host_address}{}}}}
    condition = ${if !eq{$original_domain}{$domain}}
    condition = ${if !eq{$original_domain}{}}
    condition = "${perl{check_limits}}"
    transport = spamexperts_smarthost_transport_forward
    route_list = * SMARTHOST::587
    no_more
 
I thought you could do this which makes it easier.

Create your exclude list:
/etc/spamexperts_domains

Add this to config exim:
domainlist exclude_sender_domains = lsearch;/etc/spamexperts_domains

And then add it to the router config of spamexperts like this (exim.routers.pre.conf)

senders = !*@+exclude_sender_domains

Code:
spamexperts_smarthost_router:
    driver = manualroute
    domains = ! +local_domains
    senders = !*@+exclude_sender_domains
    ignore_target_hosts = 127.0.0.0/8
    condition = "${perl{check_limits}}"
    # Exclude null sender messages from relaying via the smarthost
    condition = ${if or {{!eq{$sender_address}{}} {!eq{$sender_host_address}{}}}}
    headers_add = ${if !eq{$original_domain}{$domain}{X-Forwarded-For: $original_local_part@$original_domain}}
    headers_add = X-AuthUser: $authenticated_id
    transport = spamexperts_smarthost_transport
    route_list = $domain SMARTHOST::587
    no_more

smartexperts_smarthost_forward:
    driver = manualroute
    domains = ! +local_domains
    senders = !*@+exclude_sender_domains
    ignore_target_hosts = 127.0.0.0/8
    condition = ${if or {{!eq{$sender_address}{}} {!eq{$sender_host_address}{}}}}
    condition = ${if !eq{$original_domain}{$domain}}
    condition = ${if !eq{$original_domain}{}}
    condition = "${perl{check_limits}}"
    transport = spamexperts_smarthost_transport_forward
    route_list = * SMARTHOST::587
    no_more
Thank you, I just want to confirm you mentioned:

Add this to config exim:
domainlist exclude_sender_domains = lsearch;/etc/spamexperts_domains

Does this mean I need to add that at the bottom of my exim.config file? Or was there a specific place this needed to be in?
 
Back
Top