Discussion:
[Pkg-exim4-users] selecting smarthost based on sender address
Hans Ekbrand
2015-05-29 12:02:17 UTC
Permalink
I want to use different smart hosts depending on the sender address.

There is a old document that describes a solution, but it appears to
be for exim3, or at least not for exim4 with split-config which I use

http://www.volker-wegert.de/en/node/35

However, I used the concept outlined there and tried to apply it to
exim4 with split config.

1. Create a file /etc/exim/my.smarthosts with the following content.

***@bar.com: smarthost="smtp.bar.com" auth_name="my.username" auth_pass="some password"
***@foo.com: smarthost="smtpgw.foo.com" auth_name="my.username" auth_pass="another password"

2. Changed the smarthost field in /etc/exim4/update-exim4.conf.conf

#dc_smarthost='smtp.gmail.com'
dc_smarthost='${extract{smart_host}{${lookup{$sender_address}lsearch{/etc/exim4/my.smarthosts}{$value}fail}}}'

3. reload exim with new configuration

sudo update-exim4.conf
sudo service exim4 reload

When I tried to send a mail, I got:

2015-05-29 12:47:52 [22620] 1YyHpQ-0005sq-AT <= ***@gu.se U=hans P=local S=923 M8S=0 id=***@hans from <***@gu.se> for ***@gmail.com
2015-05-29 12:47:52 [22622] 1YyHpQ-0005sq-AT error in smarthost router: no host(s) specified for domain *
2015-05-29 12:47:52 [22622] 1YyHpQ-0005sq-AT == ***@gmail.com R=smarthost defer (-1): error in smarthost router: no host(s) specified for domain *

Which brings me to my question to the list:

What is needed to make exim use different smart hosts for different
sender addresses?
--
Note that I use Debian version 8.0
Linux hans 3.16.0-4-686-pae #1 SMP Debian 3.16.7-ckt9-3~deb8u1 (2015-04-24) i686 GNU/Linux
J G Miller
2015-05-30 20:03:17 UTC
Permalink
At 14:02h, on Friday, May 29, 2015,
in message <***@hans>,
on the subject of "[Pkg-exim4-users] selecting smarthost based on sender address",
Post by Hans Ekbrand
However, I used the concept outlined there and tried to apply it to
exim4 with split config.
The exim4 configuration with lots of macro variables for turning on and off features
is very good for black box operation where the user only wants to use one of the defined
models of operation, so my suggestion for anybody wishing to do a custom setup is to keep
things simple, and although keeping the split format with all the individual files for each
section, remove all the macro tests keeping only things that you need, and just define simple
macro variables with values specific to your case.

No doubt the Debian maintainer will strongly object to this suggestion, but it results in
following what is happening and debugging being much simpler, and it means you will have
some familiarity with what is actually happening in each file if you have reviewed each one.
Post by Hans Ekbrand
2015-05-29 12:47:52 [22622] 1YyHpQ-0005sq-AT error in smarthost router: no host(s) specified for domain *
Looking at router/200_exim4-config_primary, my guess that this is coming from

route_list = * DCsmarthost byname

and that the macro variable DCsmarthost is not defined, hence the error message

"no host(s) specified for domain *"

So I would suggest you check to see if DCsmarthost is defined. Is it beacause you are
using dc_smarthost and not CDsmarthost?

Check to see what has been generated in the unified configuration file sans macros
in /var/lib/exim4/config.autogenerated for missing parameters and ill-formed statements.

And as a bonus, here is a way to get your external ISP hostname into your headers rather than
using the internal hostname.

In router/200_exim4-config_primary, where MAIN_SMTP_SMARTHOST is defined as the ISP mailer,
/etc/exim4/conf.d/main/01_exim4-config_listmacrosdefs (this is what I meant about just using
simple macro variables names)

smarthost:
driver = manualroute
debug_print = "Router: smarthost for $local_part@$domain"
address_data = ${lookup dnsdb{ptr=${run{/usr/local/share/sh/external_ip}}}{$value}{localhost}}
domains = !+local_domains
host_find_failed = ignore
route_list = * MAIN_SMTP_SMARTHOST byname
same_domain_copy_routing = yes
transport = remote_smtp_smarthost
no_more

and then in /etc/exim4/conf.d/transport/30_exim4-config_remote_smtp_smarthost

remote_smtp_smarthost:
driver = smtp
debug_print = "Transport: remote_smtp_smarthost for $local_part@$domain"
helo_data = $address_data
headers_remove = Received:Message-Id
headers_add = "Message-Id: <$message_id@$address_data>"
headers_rewrite = CHECK_HEADERS_REWRITE \
${lookup{$1}lsearch{CONFDIR/email-addresses}{$value}fail}
hosts_try_auth = <; \
${if exists{CONFDIR/passwd.client}\
{${lookup{$host}nwildlsearch{CONFDIR/passwd.client}{$host_address}}}\
{}}
return_path = ${if match{$return_path}{CHECK_RETURN_PATH}\
{${lookup{$1}\
lsearch{CONFDIR/email-addresses}{$value}fail}}\
fail}
tls_certificate = TLS_SMARTHOST_CERTIFICATE
tls_dh_min_bits = TLS_DH_MIN_BITS


This results in the mailer getting a HELO message from the real external hostname as assigned by
the ISP and not the fictitious internal to one's lan hostname.domain. Obviously you need the
shell script to lookup the external address using curl and dig.
J G Miller
2015-05-31 17:39:10 UTC
Permalink
At 18:56h, on Sunday, May 31, 2015,
in message <***@torres.zugschlus.de>,
on the subject of "Re: [Pkg-exim4-users] selecting smarthost based on sender address",
Marc Haber wrote -
I don't think so. It's fine to simplify things if you know what you're
doing.
Okay then ;+)

I do sympathize with the maintainer that with such packages as exim4 with all
the possible models of usage and combination of variables that the maintainer
has a very difficult path the tread of offering something that will "just work"
out of the box for the casual user as well as allowing scope for very individual/site
specific customizations.

The split file format is really good in allowing this.
I would, however, suggest only simplifying files that need
local changes. That will greatly ease updates and reduce the number of
dpkg-conffile questions asked during updates.
Indeed so. What I do with all the config files (almost all from /etc) is
to create a tree /usr/usr/local/archive/debian/etc and copy all of the original
files which I change there for future reference.

When an update comes around, I can then do a diff (even fldiff for an
easy visual comparison) to see if the file has altered and if so what changes
I need to make to my customized version, and then copy the new official updated
file (dpkg-new) if different to the archive for the next time.
dc_smarthost is the writing in update-exim4.conf.conf, which gets
translated to the exim macro DCsmarthost by update-exim4.conf. So if
you directly define the macro inside exim configuration, you need to
use DCsmarthost.
Thanks for the explanation - maybe this will help Hans to fix his error.
Unfortunately, exim -bV does not check for such errors, so we cannot
flag them at daemon start or configuration build time.
Well yes, obviously one would have to write a configuration file syntax
checker which would be a an awful lot of work with a rather low value
to work hours ratio.

Loading...