I am attempting to configure exim4 under Debian 6 or 7 as follows:
- For mails being forwarded for a "virtual" domain, send directly via SMTP
- For all other mails, send via Amazon SES
The first bullet seems necessary because SES will not allow the sending of a message whose "From" address does not match a valid configured domain for that AWS account (if anybody does know a way to do this with SES, that would be a preferred solution, although I am pretty sure it is not possible).
So, right now this system works fine with SES; everything sends correctly, exim is configured correctly, etc. From that point, I defined a some new virtual domain I'd like to forward for, for example in /etc/exim4/virtual/example.com
:
user : [email protected]
I then created a new router, for example /etc/exim4/conf.d/router/090_exim4-config_virtual_redirect
containing:
sender_redirect:
driver = redirect
domains = dsearch;/etc/exim4/virtual
data = ${lookup{$local_part}lsearch{/etc/exim4/virtual/$domain}}
So far, this works fine -- exim attempts to relay messages addressed to [email protected]
to [email protected]
instead, but it fails because of the SES restriction mentioned above.
At this point, I want this router to send messages directly server-to-server, without affecting the sending of any other mails on the server.
Is this possible? I have a feeling there is one small addition I am missing here, but I haven't been able to find it.
I was able to figure this out, and it turns out the solution was pretty simple. I used a configuration directive called
redirect_router
(read about it here) which tells Exim to start processing the next address generated by the current router with the specified router, allowing it to skip over any preceding routers in sequence.I then defined my router structure as:
dnslookup_relay_to_domains
in Debian's default config)So then my redirect router looked like:
It's also necessary to edit the
/etc/exim4/update-exim4.conf.conf
file to make sure thatexample.com
is listed as a local domain, like so (only showing the relevant lines):The
internet
value tells exim to behave as an internet site that communicates with other servers directly rather than through only a smarthost. It is necessary to be able to send and receive mail directly via SMTP.The
0.0.0.0
tells Exim to bind to all IPv4 interfaces (the default is just to127.0.0.1
which will not allow the server to receive mail from remote hosts). I am not sure if there is a better/more secure setting there, but I didn't want to specify an actual external IP since it may change in the EC2 environment.Once all of that is done, you can do a
/etc/init.d/exim4 restart
to pick up the changes and everything should work.Hopefully this helps somebody out; I have no idea if this is the "right" or "best" way to do this, but it seems to be working perfectly for my purposes.