What is the "You have new mail" message in Linux/UNIX?

446

120

Sometimes, when I log into a box and 'su' to root, I get a cute little message saying I have mail (thank GOD it's not AOL).

  • Where is this mail?
  • What does it contain?
  • Who/What sent it?
  • How important is it?

Is this even actual "mail" in the same sense as email? Or is it just my system telling me something?

EDIT: In relation to this question, would I be able to send myself mail using the sendmail program like so: email@localhost?

n0pe

Posted 2011-07-04T15:23:42.730

Reputation: 14 506

1In case anyone is looking, here is powerhshell one-liner to splits that into single files readable by outlook: $i=0;(gc .\mail\root -raw) -split '[^, ]From '|%{$i++;sc mail$i.eml -value ("From " + $_)} – JDuarteDJ – 2018-04-17T15:23:02.783

lol noobcake :) – Ярослав Рахматуллин – 2018-10-31T19:35:12.260

I have this one message in there that says "This text is part of the internal format of your mail folder,..." so of course whenever I log in I am informed that I have mail. – GEdgar – 2011-07-04T20:38:56.420

1@GEdgar: This usually means you should stop using mbox mailboxes and migrate to Maildir :) – user1686 – 2011-07-04T21:12:05.193

Related: http://superuser.com/questions/149282/safely-get-rid-of-you-have-new-mail-in-var-mail-on-a-mac

– dmckee --- ex-moderator kitten – 2011-07-05T01:42:49.037

Answers

367

Where is this mail?

It's likely to be in the spool file: /var/mail/$USER or /var/spool/mail/$USER are the most common locations on Linux and BSD.

(Other locations are possible – check if $MAIL is set – but by default, the system only informs you about /var(/spool)/mail.)

Usually the spool file is in a very simple mbox format, so you can open it in a text editor or pager.

For a slightly more convenient way, most distributions come with a program called mail (or Mail, mailx). You can try mutt or alpine; you can even configure it to be sent to an outside mailbox. (See "is this real mail?" below.)

What does it contain, and who/what sent it?

Most often the messages contain output of cron jobs, or a system security report by logwatch, or similar junk. Read it and find out.

How important is it?

Depends greatly on the contents of each message.

You should at least scan the subject headers – often people ignore the mail for months never realizing that their daily cron jobs fail.

Is this even actual "mail" in the same sense as email? Or is it just my system telling me something?

Yes to both – it's generated by your system telling you something, but it's also actual email and can be handled as such.

You can (and should) configure your mail software – the "MTA" aka /usr/sbin/sendmail – to forward the messages to your personal mail address. The exact instructions vary depending on which MTA (if any) you have installed, whether this is a personal computer or a server, whether you have your own domain or use a @gmail.com, and so on.

Note that /usr/sbin/sendmail nowadays is a shared API and doesn't necessarily mean the original Sendmail MTA. In fact, you shouldn't use Sendmail, but something more modern like OpenSMTPD, Postfix, or Exim4. All of them provide the same /usr/sbin/sendmail tool, but they're easier to configure, more secure, and just as powerful.

user1686

Posted 2011-07-04T15:23:42.730

Reputation: 283 655

3Good answer. Had you added links with information on how to configure OpenSMTPD, Postfix or Exim4 to forward mail to your normal email address it would have been even better. – imolit – 2015-06-04T15:32:37.733

1

Here's a related question that shows how to setup mutt: http://askubuntu.com/a/499335/75735

– KalenGi – 2016-11-08T10:31:17.457

Great answer. But how do I use mail to read email? The manpage doesn't say.

– jpaugh – 2017-09-19T21:39:37.163

1I viewed my mail with cat /var/mail/$USER command and removed it with rm -rf /var/mail/$USER command. – Sinan Eldem – 2017-11-26T09:04:55.213

@grawity should I delete the files in /var/mail/ when I read them or just clear the text inside them? thank you! – yaylitzis – 2018-02-06T13:27:14.073

Is this the sendmail which was written by ESR? – Adam Arold – 2018-11-21T16:59:33.997

@AdamArold: No on both counts. "The original Sendmail" wasn't written by ESR as far as I know. Nowadays, the /usr/sbin/sendmail path doesn't refer to any specific software, but instead is a standard filename provided by a good dozen different implementations from different authors. – user1686 – 2018-11-21T22:22:56.757

219

The easiest way for me was to run the following in a terminal:

cat /var/spool/mail/root

Maclovin

Posted 2011-07-04T15:23:42.730

Reputation: 2 346

14Or just less $MAIL if you want to navigate. – Walf – 2016-06-14T02:13:54.127

10Or less +G $MAIL to start at the end. – Charlie Gorichanaz – 2017-07-18T01:40:36.667

5

@Blackhawk And now even more this XKCD.

– dessert – 2017-10-21T08:55:31.333

5Best practical answer so far that actually adds to the knowledge. Now I can read the mail. I wonder why it's the bottom most answer. – CDR – 2012-11-29T16:44:16.137

39

I realize this is a pretty old question/answer, but this XKCD is relevant to the discussion. (hint: hover text)

– Blackhawk – 2014-05-07T21:05:34.180

64

For anyone wondering how to read these messages one by one, you can just use 'mail'

$ mail

Then type a message number from the list which you want to read.

To goto the next message you can type 'next', another useful command is 'delete'..

To see more about how the mail program works, see the output of man mail.

Dominic Williams

Posted 2011-07-04T15:23:42.730

Reputation: 741

4// , This doesn't actually work, on CEntOS 6. In that case, one must use $ mailx. – Nathan Basanese – 2016-01-16T00:06:58.440

9On Ubuntu 16.04, I need to first install mailutils by running apt install mailutils – Edwin Yip – 2016-07-17T04:01:46.307

On Amazon EC2 instances, you can install it using sudo yum install mail – JonDoe297 – 2017-12-20T21:45:25.330

1Works for me on macOS – juanmirocks – 2018-02-07T20:08:20.020

mail or mailx didn't work as advertised. this answer isn't very good, use mutt. – Alex Barker – 2019-10-29T16:01:38.597

41

Just to offer some clarification, it's been the tradition for a long time for UNIX boxes to run a "locally configured" mailer daemon that doesn't route messages through the Internet, but only copies messages to other users spool directories (as @John T mentioned). It is real SMTP-compliant email, it's just not routed over the Internet because it doesn't need to be.

So, if you fire up an email client (like alpine or mutt) you can send mail to other users on the system by addressing to user@hostname, or in many cases, just specifying the user. You also likely have a command line utility called mailx that can be used to send a quick email using your shell.

Now, if you want to send messages to users on systems other than the one you are logged in to, that's where the real fun begins. You'll need to configure your mailer daemon to recognize and hand off external email to a transfer agent, configure the transfer agent, and do a whole bunch of stuff I don't yet understand myself.

LawrenceC

Posted 2011-07-04T15:23:42.730

Reputation: 63 487

26

Where is this mail?

Very likely stored on your machine, in the mailbox folder for your root user (where THAT is depends on what kind of mail server you have installed). You can probably access it quite quickly through alpine.

What does it contain?

Probably just some system report type stuff. "So and so tried to login 10 times with an incorrect password".. "I wish someone would run updates on me", "driver such-and-such is failing constantly", "The NSA bot has boosted performance by 1%".. etc..

Who/What sent it?

Services on your server, most likely.

How important is it?

Depends on how important your server is.

James T Snell

Posted 2011-07-04T15:23:42.730

Reputation: 5 726

I think John's suggestion that it's stored in /var/spool/mail/root is based on a (good) assumption that you're running sendmail. I think other mail servers use different locations to store mail. – James T Snell – 2011-07-04T15:30:27.230

Is there a way for users to use the mail subsystem? – n0pe – 2011-07-04T15:31:18.070

White Phoenix: I'll take look when my mail is when I get the message again :) Is there a way for me to trigger it or is that too localized of a question? – n0pe – 2011-07-04T15:32:10.270

If you want to explore running your own mail server (that people use in a typical email sense), it'd first help to know what distro you're running? Without that info, all I'll say, is that I suggest you read up on sendmail (as you're probably running sendmail already).. – James T Snell – 2011-07-04T15:32:42.873

Most of them are running AIX but I'd like to explore this on my workstation at home running OpenSuSe – n0pe – 2011-07-04T15:37:02.057

Here's a sendmail tutorial: http://www.feep.net/sendmail/tutorial/

– James T Snell – 2011-07-04T15:40:01.570

14

This mail is typically located in /var/spool/mail/root when the (usual) default sendmail daemon is configured. It contains a RAW e-mail message that can be read by the mail utility. Who sent it can be found by running the mail utility and paging through the messages or reading the RAW headers.

The importance of the message usually depends on the previous factor, who sent it :)

Many system utilities will use the mail subsystem as a means of reporting and logging. Log watcher utilities and other services may send an e-mail to the local root user as a reminder about a specific event, such as low disk space or hardware errors. The mailer daemon will also alert you if it failed to send an e-mail outbound.

John T

Posted 2011-07-04T15:23:42.730

Reputation: 149 037

On ubuntu 16.4., I have /etc/mail.rc which is not related to sendmail – Timo – 2017-12-24T10:18:03.827

Is there a way to see how my mail subsystem is set up? – n0pe – 2011-07-04T15:29:58.413

@Max the sendmail.mc file controls configuration of the sendmail daemon on most default installs. It is typically located under /etc/mail. – John T – 2011-07-04T15:34:39.880

@Max I would strongly recommend reading through a tutorial such as http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch21_:_Configuring_Linux_Mail_Servers#The_.2Fetc.2Fmail.2Fsendmail.mc_File to help you configure the mailer daemon as desired.

– John T – 2011-07-04T15:39:35.810

12

less +G /var/spool/mail/root

shows the latest mails, at the end if the file.

Directly showing the mail file is a good idea, but using cat can easily go wrong. You do not want all mails scroll by, if there are many messages, or very long messages in the file. I just saw one with 150MB, two million lines.

If you are not root:

sudo less +G /var/spool/mail/root

The +G option is used to show the newest message first; It is not at the top of the file, but on the end.

It is an option of less, making it show the last page of the file after starting. That show the last message (newest), if it fits to one page, or the end of that otherwise.

The file name may be /var/spool/mail/mail instead of /var/spool/mail/root

Volker Siegel

Posted 2011-07-04T15:23:42.730

Reputation: 1 188

// , Excellent breakdown. This answer would be especially useful for those folks who don't easily know what to do with the file. – Nathan Basanese – 2016-01-16T00:20:57.347

4

In case anyone else is wondering, +G "causes less to initially display each file starting at the end rather than the beginning." (https://linux.die.net/man/1/less)

– Sam – 2016-11-24T14:03:09.310