Mailing List Archive

Configuring Exim to make manual routing decision based on MX records of recipient domains
Hi guys,

I am new at customizing Exim and I am using an ESP to get my customers'
emails to be received in the Inbox of Gmail/Hotmail/Yahoo. At the moment I
do this by manually routing the domains (manualroute router of Exim for
domains gmail.com, yahoo.com, hotmail.com, ymail.com, etc.)

There is a problem with this configuration. If one day one of these free
email providers offer new domains or in Google's case people use Google
Apps for their domain or Windows Live Domains, there is no way I can list
down all the domains for the Exim manualroute router. These emails would
then be delivered through the normal remote_delivery and I cannot take
advantage of my ESP services. I did my research on this and found out that
I need a dnslookup router with mx_domains directive (rather than
manualroute) to be able to make decision based on the MX of the recipients'
domain.

Now I came to a problem where I cannot use mx_domains inside manualroute,
nor use route_list inside dnslookup. How do I get around this problem? Is
there a clever trick to be able to achieve what I need? I was thinking the
solution shall remain to be a manualroute router with additional condition
to do a lookup on the recipients' domains MX records. Can a perl script be
implemented to achieve this?

I tried using ignore_target_hosts in manualroute, but unfortunately that
didn't work because the target_hosts would then be my ESP's server rather
than the recipient domain's MX.

Thanks in advance!

References:
http://www.volker-wegert.de/en/node/35
https://lists.exim.org/lurker/message/20050813.081640.a0005637.de.html#exim-users
--
## 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: Configuring Exim to make manual routing decision based on MX records of recipient domains [ In reply to ]
| [...] I did my research on this and found out that I need a dnslookup
| router with mx_domains directive (rather than manualroute) to be able
| to make decision based on the MX of the recipients' domain.
|
| Now I came to a problem where I cannot use mx_domains inside
| manualroute, nor use route_list inside dnslookup. How do I get around
| this problem? Is there a clever trick to be able to achieve what I
| need? I was thinking the solution shall remain to be a manualroute
| router with additional condition to do a lookup on the recipients'
| domains MX records. Can a perl script be implemented to achieve this?

You can do what you want with a special version of the SMTP transport
that uses the 'hosts' and 'hosts_override' SMTP transport settings:

remote_smtp_esp:
debug_print = "T: remote_smtp_esp for $local_part@$domain"
driver = smtp
hosts = ESP_HOST
hosts_override = true

In your special mx_domains-based dnslookup router, just set this
transport instead of your regular SMTP transport.

(We use a version of this here to do special routing for some outgoing
messages.)

- cks

--
## 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: Configuring Exim to make manual routing decision based on MX records of recipient domains [ In reply to ]
Hi Chris,

Thanks for the insight!

I couldn't get it working with mx_domains. I guess I misread the docs and
somehow had this idea that mx_domains directive can be used for my need.

I got it working now with the following:

smarthost_dkim:
driver = dnslookup
domains = !+local_domains
require_files =
"+/var/cpanel/domain_keys/private/${sender_address_domain}"
transport = remote_smtp_smart_dkim
ignore_target_hosts = ! /etc/mail_ips_of_domains_to_be_relayed

smarthost_regular:
driver = dnslookup
domains = !+local_domains
transport = remote_smtp_smart_regular
ignore_target_hosts = ! /etc/mail_ips_of_domains_to_be_relayed

remote_smtp_smart_dkim:
driver = smtp
hosts_require_tls = *
interface = ${if exists
{/etc/mailips}{${lookup{$original_domain}lsearch{/etc/mailips}{$value}{${lookup{$sender_address_domain}lsearch{/etc/mailips}{$value}{${lookup{${perl{get_sender_from_uid}}}lsearch*{/etc/mailips}{$value}{}}}}}}}}
helo_data = ${if exists
{/etc/mailhelo}{${lookup{$original_domain}lsearch{/etc/mailhelo}{$value}{${lookup{$sender_address_domain}lsearch{/etc/mailhelo}{$value}{${lookup{${perl{get_sender_from_uid}}}lsearch*{/etc/mailhelo}{$value}{$primary_hostname}}}}}}}{$primary_hostname}}
dkim_domain = $sender_address_domain
dkim_selector = default
dkim_private_key = "/var/cpanel/domain_keys/private/${dkim_domain}"
dkim_canon = relaxed
hosts_require_auth = *
hosts = smtp.sendgrid.net
hosts_override = yes

remote_smtp_smart_regular:
driver = smtp
hosts_require_tls = *
interface = ${if exists
{/etc/mailips}{${lookup{$original_domain}lsearch{/etc/mailips}{$value}{${lookup{$sender_address_domain}lsearch*{/etc/mailips}{$value}{${lookup{${perl{get_sender_from_uid}}}lsearch*{/etc/mailips}{$value}{}}}}}}}}
helo_data = ${if exists
{/etc/mailhelo}{${lookup{$original_domain}lsearch{/etc/mailhelo}{$value}{${lookup{$sender_address_domain}lsearch{/etc/mailhelo}{$value}{${lookup{${perl{get_sender_from_uid}}}lsearch*{/etc/mailhelo}{$value}{$primary_hostname}}}}}}}{$primary_hostname}}
hosts_require_auth = *
hosts = smtp.sendgrid.net
hosts_override = yes

The file /etc/mail_ips_of_domains_to_be_relayed is a list of IPs of the MX
of Gmail/Hotmail/Yahoo in CIDR format.

This works as I expected, Exim with recipient's domain MX-based routing
decision. :)

Much thanks, Chris!


Cheers,
Andryan


On Thu, Aug 29, 2013 at 10:24 PM, Chris Siebenmann <cks@cs.toronto.edu>wrote:

> | [...] I did my research on this and found out that I need a dnslookup
> | router with mx_domains directive (rather than manualroute) to be able
> | to make decision based on the MX of the recipients' domain.
> |
> | Now I came to a problem where I cannot use mx_domains inside
> | manualroute, nor use route_list inside dnslookup. How do I get around
> | this problem? Is there a clever trick to be able to achieve what I
> | need? I was thinking the solution shall remain to be a manualroute
> | router with additional condition to do a lookup on the recipients'
> | domains MX records. Can a perl script be implemented to achieve this?
>
> You can do what you want with a special version of the SMTP transport
> that uses the 'hosts' and 'hosts_override' SMTP transport settings:
>
> remote_smtp_esp:
> debug_print = "T: remote_smtp_esp for $local_part@$domain"
> driver = smtp
> hosts = ESP_HOST
> hosts_override = true
>
> In your special mx_domains-based dnslookup router, just set this
> transport instead of your regular SMTP transport.
>
> (We use a version of this here to do special routing for some outgoing
> messages.)
>
> - cks
>
--
## 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/