User Specific Smarthost Exim4 Configuration on Debian Etch and Debian Lenny


I have a DSL connection at home and until now I have relayed all outgoing email via the smtp server of my DSL provider. I used the default "mail send by smarthost; received via SMTP or fetchmail" exim4 configuration of Debian.

All this was working fine, except for the following. As an anti-spam measure gmx (and probably other email providers) check whether the email originates from the system that is specified in the From address. For some of my family members this is obviously not the case: They have a email account but their outgoing email never sees an server (because it is relayed via my DSL provider). Gmx therefore classifies all our Emails as spam, which we are not particularly happy about.

Why not relaying via then?

Because there are more local email users (notably the debian popularity contest) and only accepts email with a from address of an account.

I need to relay the email of users via and the email of other users via other systems!

Solution: Exim smarthost database lookup

As solution I let exim query a data base that matches From-addresses with smarthosts. This way the email of every user can be relayed via a different system.

In the following I assume an "unsplit configuration" of exim4 (I answered NO to the relevant question of "dpkg-reconfigure exim4-config"). If you use a split configuration you have to modify a different file, probably /etc/exim4/conf.d/main/01_exim4-config_listmacrosdefs.

Debian Etch

For Debian Etch look for the following lines in /etc/exim4/exim4.conf.template:
#for satellite and smarthost-systems
.ifndef DCsmarthost
DCsmarthost = DEBCONFsmarthostDEBCONF
and change them into
#for satellite and smarthost-systems
.ifndef DCsmarthost
DCdefault_sh = DEBCONFsmarthostDEBCONF
DCsmarthost = ${lookup{$sender_address}lsearch{CONFDIR/smarthost_per_user}{$value}{DCdefault_sh}}

Debian Lenny

In Debian Lenny the definition of the DCsmarthost macro is generated by update-exim4.conf, therefore we cannot change the original definition. Therfore, in /etc/exim4/exim4.conf.template after the lines
# debconf-driven macro definitions get inserted after this line
UPEX4CmacrosUPEX4C = 1
# Fix to use user specific smarthosts. Save the configured smarthost
# in DCdefault_sh and do a lookup for DCsmarthost.
DCdefault_sh = DCsmarthost
DCsmarthost == ${lookup{$sender_address}lsearch{CONFDIR/smarthost_per_user}{$value}{DCdefault_sh}}
Here we save the configured value of DCsmarthost in DCdefault_sh and overwrite DCsmarthost afterwards.

Explanation / Usage

What it does: The expansion of the DCsmarthost macro is now a file lookup that takes the sender address and searches for it in the file /etc/exim4/smarthost_per_user. If found it takes the remainder of the line as smarthost. If not found it uses DCdefault_sh as default, which is set to what configured as smarthost in the exim4 configuration.

The file smarthost_per_user looks as follows:

xxx@yy.zz: smarthost.xx.zz
[Somebody seems to block me from connecting to the default smtp port 25 at, therefore I use port 587.]

To use this new exim configuration go through dpkg-reconfigure exim4-config or do

update-exim4.conf; /etc/init.d/exim4 restart

Other Related issues

I configured /etc/email-addresses to let exim rewrite local user names into their most preferred email addresses.

In contrast to my DSL provider the smtp server of requires some authentication. I set this up in /etc/exim4/passwd.client.


I have simplified/changed the solution proposed in Debian bug #399185.

Home Software Overview

last changed on 20 Sep 2011 by Hendrik