Linux you got mail

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

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 ?

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.

In 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 " + $_)>

7 Answers 7

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.

Читайте также:  Linux mint window menu

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.

Good 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.

I viewed my mail with cat /var/mail/$USER command and removed it with rm -rf /var/mail/$USER command.

@Andyc: Make the cronjobs not produce output. Use the appropriate «—quiet» or «silent» option of the program being run, or fix the job to not produce error messages by adding error checks where appropriate, or redirect the whole job’s output to /dev/null like in shell (cronjobs use shell syntax).

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

Best 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.

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

For anyone wondering how to read these messages one by one, you can just use ‘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 .

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.

Читайте также:  Проверить работу dhcp linux

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.

Источник

«You have mail» welcome message with no mail

When I login to one of my stations I get this output saying I have mail. But then running the mail commands Says I don’t have any email. What can I do to repair this problem?

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. You have mail. Last login: Thu Nov 17 01:38:35 2016 from ***.***.***.*** psms1@psms:~$ mail No mail for psms1 psms1@psms:~$ 

3 Answers 3

Your mailbox is probably corrupted or some email client left there a residual byte/character. Another email client can even say it is empty.

As it is empty, the easier approach it to delete it with the command:

As such, it will be recreated the next time you receive a message, and the mail command will be happy with it.

This is reported when the atime on your mail spool file(s) is the same as the mtime (i.e. the last access modified the file). It might be easier to think about the case where the access time is after the modification time — this implies you read your mail and the message is suppressed.

If you don’t have new mail then something else most be changing the mtime on your spool file.

I tried Ribeiro’s solution on a shared Mac with this same problem and was asked for sudo permissions I didn’t have.

I tried echo «» > /var/mail/user but it didn’t fix the problem.

Instead, cat /dev/null > /var/mail/user worked perfectly as a substitute to bypass the need for sudo permissions.

Edited on Thu, 06 Jul 2023 12:03:17 +0000: The mail path on the Mac was /var/mail/user , not /var/spool/mail/user as was my original answer.

Источник

“You have new mail” message in Linux/UNIX

A common scenario on most Linux systems is the following: «When I log into a box and ‘su’ to root, I get a cute little message saying I have mail.«.

  • 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?

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.

Читайте также:  Настройка своего впн линукс

Linux you got mail

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.

What does it contain? 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.

Read your messages in Ubuntu

To see what messages you received from the command line, this command will reveal the message(s):

Show mails in /var/mail/root

The message could look like this:

From [email protected] Wed Jul 29 12:05:26 2015 Return-Path: Received: from hostname (localhost [127.0.0.1]) by hostname (8.14.4/8.14.4/Debian-4.1ubuntu1) with ESMTP id t6TG5QKu001540 for ; Wed, 29 Jul 2015 12:05:26 -0400 Received: (from [email protected]) by hostname (8.14.4/8.14.4/Submit) id t6TG5QYK001533; Wed, 29 Jul 2015 12:05:26 -0400 Date: Wed, 29 Jul 2015 12:05:26 -0400 Message-Id: [email protected]> To: [email protected] From: [email protected] Auto-Submitted: auto-generated Subject: *** SECURITY information for hostname *** 
hostname: Jul 29 12:05:26 : root : unable to resolve host hostname

Removing messages from /var/mail/root

To purge these messages and to get rid of the message you received on logging in, you can simply delete it with this command:

Do not forget to include the > sign, otherwise it won’t work.

Источник

Оцените статью
Adblock
detector