What is the Ubuntu way for system administrators to receive system notifications, which typically take the form of e-mail sent to the root account?

Examples of such notifications are the output of cron jobs, or degraded RAID notifications.

On a pretty much default Ubuntu 10.04 installation, I can't find any way that anything happens to root's mail other than being deposited in /var/mail/root. How are users supposed to 1. discover it and 2. read it as it arrives?

I observe that on a warty, the installer added root: myusername to /etc/aliases. So back then the user who installed the system if (s)he read the local mail. So there seems to have been a regression somewhere along the way. Still this was not a complete solution, because Ubuntu users can't be expected to be aware that they have local mail and should set up their mail client to read it.

ADDED: given current replies, a server user should be able to cope, provided he's aware of the issue. Fair enough. But consider J. Random Desktop User, who doesn't know how to use a command line, and only knows how to click the mailbox icon to read his mail. How can he be notified that his system wants to tell him something? (Allow a one-time intervention by a more competent user if that's unavoidable.)

  • 1
    I managed to get KMail to read my local mail using some very strange hacks I found, but since the update to 11.10 I'm lost – Dirk Hartzer Waldeck Nov 17 '11 at 14:48
  • I recently did a long tutorial on this very subject, although relating to Thunderbird: see askubuntu.com/questions/192572/… – user76204 Oct 30 '12 at 23:45
  • @Mik That, with a little something about installing postfix at the top, would make a nice answer here. – Gilles Oct 30 '12 at 23:48
  • @Gilles Thanks, although I probably would have to shorten or delete the answer at the other question, so there wouldn't be duplication. – user76204 Oct 30 '12 at 23:53
  • @Mik No, it would be fine to repost substantially the same answer (not exactly, since here you'd need to start by installing an MTA). The questions aren't duplicate: there are answers here that wouldn't work on the other question and vice versa. It does happen that sometimes 90% of an answer can be recycled for another question, that's fine. – Gilles Oct 30 '12 at 23:56

Encouraged in the comments by Gilles, I have adapted and expanded another answer:

(I am running Ubuntu 12.04.1 LTS, but the general setup process should apply to previous and future Ubuntus)

The first thing to do is to install a Mail Transfer Agent (MTA) so the mail can be relayed to a mail User Agent (MUA) such as Thunderbird. This is only necessary because we are dealing with local mail and want to be able to send and receive it; with normal remote gmail type accounts, only a user agent such as Thunderbird is necessary.

I use postfix, which itself is an alternative to sendmail, of which there are commercial and open source versions. More information about postfix's capabilities is at the official site and users may find that the mailing lists contain useful information if any issues arise.

So, to install the program, run

sudo apt-get install postfix

You can either configure it when it is installed, or decline the offer and later run

sudo dpkg-reconfigure postfix

to create the important config file (/etc/postfix/main.cfg). If you ever manually edit this file, which is not necessarily recommended, you must run sudo newaliases and sudo service postfix restart afterwards to apply the changes.

Postfix is pretty straightforward to setup, although you may have some particular settings that you wish to apply. In the first screen you see below, you must choose the local option for your mail:

enter image description here

Then on the next screen choose your 'mail name'; it is usually the same as /etc/hostname. You can accept the defaults for most of the following screens.

enter image description here

When it mentions /etc/aliases and the Root and Postmaster recipient (as above), you can fill in your user name, but make sure you check your aliases file is as it should be by reading the next section of this tutorial.

First, as also recommended in this discussion, your /etc/aliases should be like this if it is setup correctly:

postmaster:    root
root:   mike 

If not, edit it with sudo nano /etc/aliases, and then run sudo newaliases and sudo service postfix restart so that the configuration is updated. Postfix's aliases feature allows mail to be redirected, so the setup is very important for the rest of this tutorial.

As also noted in the above link, you need to create a .forward file containing your username and localhost: e.g. mike@localhost so that root's mail will be forwarded to you. To do this, enter these commands:

sudo touch /root/.forward

and then run

sudo nano /root/.forward

to place your user: e.g. mike@localhost in the file and save it.

In addition, I found it was necessary to add your user to the mail group so that Thunderbird could access the mail files:

sudo adduser $USER mail

and then logout and login for the changes to take effect. There is no need to chown or chmod any files, as some articles might suggest, and adding your user to the mail group is much better practice and avoids any direct changing of the permissions on the root filesystem.

Now for the Thunderbird configuration. Go to edit > account settings > account actions > add other account > select Unix spoolmail and in the next screen put your username in the first box and place yourusername@localhost in the second box.

enter image description here enter image description here

Now, go to your new account in account settings and select server settings and select the local directory as /var/mail or /var/mail/username (if setup), as in the screenshot below.

enter image description here

As per the instructions in this article you will need to configure the smtp server if you want to test the account by sending a mail to root@localhost and then clicking get mail in Thunderbird to receive it, as root's mail is being redirected to youruser@localhost.

Go to account settings > outgoing server and choose to add a new one. The settings should be as in the screenshot below:

enter image description here

Now, finally test your account by composing a mail to root@localhost and then a few seconds later clicking get mail on your account. You should see an email like this:

enter image description here

Some programs or logs will need to be configured so that they send mail to root, but that can be decided as you find the need. This article should hopefully be useful as it is not always straightforward to set up Thunderbird to receive local mail.

  • Works for 17.04, I didn't touch the groups. – Artyom Mar 28 '17 at 13:11

If this is a server I would strongly suggest you alias root to a real email address so you get your email delivered to your administrators It is as easy as adding

# Person who should get root's mail
root:   all_administrators@mydomain.com

to the end of /etc/aliases

Alternatively you can configure mail to be aliased to your local username and then when you log in you will get the message "You have mail", which you can check using the mail command or by installing pine / mutt /alpine or something similar on that server..

  • 1
    Thanks, that's a good enough explanation for a server admin, I suppose. But how do I explain this to J. Random desktop user, who is definitely not going to use the command line, but would like to know if his disks are failing? – Gilles Aug 14 '10 at 18:09
  • 1
    You question starts: "What is the Ubuntu way for system administrators to receive system notifications...". But anyway, for desktop users, to keep an eye on the system messages they could use gnome-system-log to view logs (which is already installed on a default Ubuntu Desktop as part of gnome-utils package) or add "root: username" to the end of /etc/aliases. I agree this a weak solution and perhaps a bug should be raised to get this feature added back in as there is no GUI way to do this on a default Ubuntu install. – Richard Holloway Aug 15 '10 at 22:02
  • The alias for server admins is best. You could also sudo su - then use a CLI client. But if your seriously admining a box, make the alias. Normal users don't need to see this mail. They have other means for notification messages. If they want to, then they can create the alias. It makes perfect sense for this to be off by default. – coteyr Nov 4 '12 at 20:09
  • Once you have an alias set up is there a way to forward all the mail that already exists? – John Feb 16 '14 at 16:06
  • There doesn't seem to be a /etc/aliases file. Does that require running a mail server for it to get generated? – Thufir Feb 13 '17 at 14:46

I am personaly using a mailer agent called nullmailer. It acts as a mail proxy, and transfers all mails sent to root to a mail address of your choice.

You need to set its settings in conf files under /etc/nullmailer. Basically : give it your mail porvider address and credentials, and the adress you want to receive the root emails on.

You can install it with

sudo apt-get install nullmailer

You can get more information on its setup here : http://jviz.research.iat.sfu.ca/wiki/index.php?title=HOWTO_Setup_Nullmailer

  • +1 thanks for the link (and the teeny MTA concept embodied therein) – msw Aug 14 '10 at 14:45

Currently there is no notification to the user that a root local mailbox even exists, because user != root If you needed to check the mailbox you could type the following: sudo mail to launch the mail application under root.

You could also log in as root on that server. To unlock the root password simply type: sudo passwd and enter a new password for root.

  • 1
    With a test user in 10.04 using the the default gnome-based interface, or the default kde-based interface, or the default lxde-based interface, I don't see any kind of notification that there is something in /var/mail/$USER either. – Gilles Aug 14 '10 at 18:11

An alternative - I archive all root mail to some files, and then delete the original mail.

I cron a script (here is the key part) -

if `/usr/bin/mail -e`; then
   /usr/bin/mail --print 2>&1 > /tmp/email_${date +"%Y-%m-%d_%H.%M").log
   echo ‘d *’ | /usr/bin/mail -N > /dev/null
exit 0

This keeps things tidy and I can keep an eye on it. I could email a daily mail file out to an external email id, etc...

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.