Exim – Email to Root Ignores /etc/aliases and /root/.forward

emaileximUbuntu

dpkg-reconfigure exim4-config asks for a domain name to "qualify" email addresses of local users such as root. Let's say I've set this setting to qualified.example.com – this causes all email sent to simply root to go to root@qualified.example.com.

I instead want all email to root to be sent to example@gmail.com, but I want the qualified domain name setting left set to qualified.example.com for other reasons.

I've added this line to /etc/aliases

root: example@gmail.com

And I've also put example@gmail.com in /root/.forward

I've run newaliases and restarted exim, but no matter what I do, mail to root continues to always try to send to root@qualified.example.com, which doesn't even exist.

How can I force email to root to go to example@gmail.com?

This is on Ubuntu Server 14.04

My /etc/exim4/update-exim4.conf.conf looks like this:

dc_eximconfig_configtype='internet'               
dc_other_hostnames=''                             
dc_local_interfaces='127.0.0.1'                   
dc_readhost=''                                    
dc_relay_domains=''                               
dc_minimaldns='false'                             
dc_relay_nets=''                                  
dc_smarthost=''                                   
CFILEMODE='644'                                   
dc_use_split_config='false'                       
dc_hide_mailname=''                               
dc_mailname_in_oh='true'                          
dc_localdelivery='mail_spool'              

When I ran dpkg-reconfigure exim4-config I answered the qualified domain question like so:

The 'mail name' is the domain name used to 'qualify' mail addresses without a domain name.                  

This name will also be used by other programs. It should be the single, fully qualified domain name (FQDN). 

Thus, if a mail address on the local host is foo@example.org, the correct value for this option would be    
example.org.                                                                                                

This name won't appear on From: lines of outgoing messages if rewriting is enabled.                         

System mail name:                                                                                           

qualified.example.com_________

Although that setting doesn't appear in /etc/exim4/update-exim4.conf.conf. Should it?

I've noticed that the same issue happens on my Debian servers too. I must be completely misunderstanding something about Exim and/or the /etc/aliases file, because they all seem to ignore my /etc/aliases root: example@gmail.com entry and they always send root's mail to root@qualified.example.com no matter what I try. It also seems odd that a simple forwarding rule is so dependent on the mail servers main configuration?

Best Answer

Your host doesn't sufficiently know that it is supposed to be qualified.example.com. A local delivery to root is rewritten as root@qualified.example.com, which is (wrongly) considered to be elsewhere, so an off-host delivery is attempted.

You need to complete the process telling exim4 that your local host really is qualified.example.com. Then, when it delivers to root, rewritten as root@qualified.example.com it will consider this as local delivery. It will then check the /etc/aliases file and perform off-host delivery to example@gmail.com per your instructions.

Let's assume your host's real DNS name is myhost.contoso.com. Rerun dpkg-reconfigure exim4-config and include these settings:

  • System mail name: myhost.contoso.com
  • Other destinations for which [local] mail is accepted: myhost : qualified.example.com
  • Domains to relay mail for: {empty}
  • Machines to relay mail for: {empty}

Then run update-exim4.conf and invoke-rc.d exim4 restart

Related Question