I have setuped an Exim4 server on my debian wheezy server. This mail server only sends mail coming from localhost. The purpose is sending mail for my website.
I have cron tasks and other services generating mails for root
user.
These mails are not stored in /var/mail
as before, but sent by exim to root@mydomain.com
.
I try to make exim send mails for root
to mypersoaddress@gmail.com
rather than root@mydomain.com
.
I tried adding a .forward
in /root
with mypersoaddress@gmail.com
as content. I tried also changing /etc/aliases
with root: mypersoaddress@gmail.com
. The fact is that routing works for root@localhost
but not for root
which is resolved as root@mydomain.com
I tested how routing is resolved with exim -bt
:
root@srv02:~# exim -bt root@localhost
R: system_aliases for root@localhost
R: dnslookup for mypersoaddress@gmail.com
mypersoaddress@gmail.com
<-- root@localhost
router = dnslookup, transport = remote_smtp
host gmail-smtp-in.l.google.com [173.194.67.27] MX=5
host alt1.gmail-smtp-in.l.google.com [74.125.143.27] MX=10
host alt2.gmail-smtp-in.l.google.com [74.125.25.27] MX=20
host alt3.gmail-smtp-in.l.google.com [173.194.64.27] MX=30
host alt4.gmail-smtp-in.l.google.com [74.125.142.27] MX=40
root@srv02:~# exim -bt root
R: dnslookup for root@mydomain.com
root@mydomain.com
router = dnslookup, transport = remote_smtp
host aspmx.l.google.com [173.194.78.27] MX=1
host alt1.aspmx.l.google.com [74.125.143.27] MX=5
host alt2.aspmx.l.google.com [74.125.25.27] MX=5
host alt4.aspmx.l.google.com [74.125.142.27] MX=10
host alt3.aspmx.l.google.com [173.194.64.27] MX=10
I bet this is a matter of how my server is configured (rather than how exim is configured). But to understand well I would like to have a solution for both :
- how to have
root
resolved asroot@localhost
? - how to have
root@mydomain.com
routed tomypersoaddress@gmail.com
?
Best Answer
The debug output you are using indicates you're using a Debian style configuration system. I'm going to refer to this as exim4 in order to make it clear that there is some extra configuration magic occurring beyond the default exim config that comes in the source. Anybody reading this later needs to clearly understand that some of this suggestion does not apply unless they are running Debian style exim configs.
The difference in your -bt output gives a clue:
In the first one, it knew to look in the system_aliases router because "localhost" is configured to be one of the domains that is allowed to look in the aliases file. But in the second one, it skipped over that aliases file because "mydomain.com" is not in that list. In exim4, that list is the MAIN_LOCAL_DOMAINS macro.
By my estimation, one of these things is probably going to solve your problem. Items 2 and beyond are potential adjustments to your exim.conf. Since you run exim.4, you need to be adjusting Debian mail configuration files in /etc/exim/ and then run exim4-conf.conf or something like that to have those changes read in and generate the new configuration file (/var/lib/exim4/config.autogenerated*) that exim4 actually uses.: