System mails does not go to root - exim4 mutt sendmail postfix

The problem

In a Debian 7 system I discovered that all system mails were delivered not to the root account, but to another user. Internal mails like crontab responses never hit the root account, quite bad.

The finding of the solution

It turned out to be a cake-on-cake problem as it often is in Linux.

In /etc/aliases you may setup aliases for different (mail) accounts. Quite simple file, a semicolon separates what should go where. Or at least I thought so. In the bottom of the file I thought I found the problem, the following line stood there:

root: wrong_username

I changed it to root: root and then I ran newaliases as it's told on the web. I also restarted exim4, doing service exim4 restart, then I sent a mail to root. Did not work.

I found out that exim4 has a weird "router" setup that throws root mails into /var/mail/mail. This rule is located at:
/etc/exim4/conf.d/router/mmm_mail4root. I messed with that file too as it was invalid lines like user = mail, group = mail and data = /var/mail/mail. Did the same procedure as above to reload and send a mail to root, did not work, nothing was delivered.

Back to the search engine again I discovered it is some kind of security thing of exim4. Important mails should be read by humans and therefore root mails should not appear in root account where they never are read. Besides exim4 cannot run or write as root since 4.24 or something like that.

The I-won't-mail-root-thing of exim4 is locked down twice(!). First hardcoded in source code and then in a config somewhere.

The solution

To fix it and finally get your mails at root as it should be you have to wade through source code fiddling, configurations of it and making sure it also runs as root which it probably will whine about. 

Or... kick it all out and replace it with sendmail. Now it's been told too that sendmail has security issues, but who cares if we're talking about inhouse mails behind firewalls.

I had to install sendmail-bin before sendmail, it whined about that exim4 was blocking it. Installing sendmail wiped exim4 (good bye, happy to see you go). Only installing sendmail-bin first was not working, got errors in /var/log/syslog, so afterwards I also installed sendmail. This is what I did:

apt-get install sendmail-bin
apt-get install sendmail


One convenient thing with this mail client is that it is dumping read mails and when you open the inbox it's nicely empty or only contain unread mails. Too bad this is not default in Debian. To fix it I had to edit ~/.muttrc and add the line:

set move=yes

Then it started tossing away mails like it should.


An alternative to sendmail and exim4 is postfix, which has the same problem as exim4 - it does not want to send mails to root.

By default /etc/aliases sends root mails to the user specified there, on Debian Jessie 8 this is the first user that is created when the system is installed.

As above with the other mail systems you need to edit /etc/aliases and set root: root there.
Then run newaliases so postfix reloads.

But this is not enough, mails will now be dispatched to /var/mail/nobody not to /var/mail/root. Postfix gives a similar explanation as exim4 on their site, you should not be logged in as root and you should not receive mails as root.

A workaround is the following, which goes to the mail directory and then creates a symbolic link from the nobody file to the root file:

cd /var/mail
ln -s nobody root

By running mutt as root you may now read and also write mails in the name of root. Even the notifier seems to work, I tried to send a mail from a normal account to root and I got a line about a new mail in the console after making a new line.

This is a personal note. Last updated: 2015-07-21 20:55:25.







Don't forget to pay my friend a visit too. Joakim