204

Few days ago I got this message in my terminal window: enter image description here

What does that mean? I've never seen that before.

That was messages from xCode bots.

bots

Thanks for the help.

3
  • 14
    Run mail and read your mail.
    – Blender
    Mar 4, 2014 at 4:45
  • For first - i have not any unreaded mails. For second - why this string did appear now? Ive never see her before. Mar 4, 2014 at 4:46
  • 2
    This question appears to be off-topic because it is better suited for apple.stackexchange.com
    – Monolo
    Apr 17, 2014 at 10:37

5 Answers 5

337

I was also having this issue of "You have mail" coming up every time I started Terminal.

What I discovered is this.

Something I'd installed (not entirely sure what, but possibly a script or something associated with an Alfred Workflow [at a guess]) made a change to the OS X system to start presenting Terminal bash notifications. Prior to that, it appears Wordpress had attempted to use the Local Mail system to send a message. The message bounced, due to it having an invalid Recipient address. The bounced message then ended up in the local system mail inbox. So Terminal (bash) was then notifying me that "You have mail".

You can access the mail by simply using the command

mail

This launches you into Mail, and it will right away show you a list of messages that are stored there. If you want to see the content of the first message, use

t

This will show you the content of the first message, in full. You'll need to scroll down through the message to view it all, by hitting the down-arrow key.

If you want to jump to the end of the message, use the

spacebar

If you want to abort viewing the message, use

q 

To view the next message in the queue use

n

... assuming there's more than one message.

NOTE: You need to use these commands at the mail ? command prompt. They won't work whilst you are in the process of viewing a message. Hitting n whilst viewing a message will just cause an error message related to regular expressions. So, if in the midst of viewing a message, hit q to quit from that, or hit spacebar to jump to the end of the message, and then at the ? prompt, hit n.

Viewing the content of the messages in this way may help you identify what attempted to send the message(s).

You can also view a specific message by just inputting its number at the ? prompt. 3, for instance, will show you the content of the third message (if there are that many in there).

DELETING MESSAGES

Use the d command (at the ? command prompt )

d [message number]

To delete each message when you are done looking at them. For example, d 2 will delete message number 2. Or you can delete a list of messages, such as d 1 2 5 7. Or you can delete a range of messages with (for example), d 3-10. You can find the message numbers in the list of messages mail shows you.

To delete all the messages, from the mail prompt (?) use the command d *.

As per a comment on this post, you will need to use q to quit mail, which also saves any changes.

If you'd like to see the mail all in one output, use this command at the bash prompt (i.e. not from within mail, but from your regular command prompt):

cat /var/mail/<username>

And, if you wish to delete the emails all in one hit, use this command

sudo rm /var/mail/<username>

In my particular case, there were a number of messages. It looks like the one was a returned message that bounced. It was sent by a local Wordpress installation. It was a notification for when user "Admin" (me) changed its password. Two additional messages where there. Both seemed to be to the same incident.

What I don't know, and can't answer for you either, is WHY I only recently started seeing this mail notification each time I open Terminal. The mails were generated a couple of months ago, and yet I only noticed this "you have mail" appearing in the last few weeks. I suspect it's the result of something a workflow I installed in Alfred, and that workflow using Terminal bash to provide notifications... or something along those lines.

Simply deleting the messages

If you have no interest in determining the source of the messages, and just wish to get rid of them, it may be easier to do so without using the mail command (which can be somewhat fiddly). As pointed out by a few other people, you can use this command instead:

sudo rm /var/mail/YOURUSERNAME
5
  • 18
    Note you will need to use q to exit mail to save the changes to disk Feb 18, 2016 at 17:28
  • The 'n' and 'd' commands following using 't' to display the first message don't perform as you describe for me. 'd' just seems to scroll, and 'n' has something to do with regular expressions. Feb 7, 2017 at 11:46
  • @NathanHornby You'll need to use that command once you're back at the ? command prompt. t will give you a full readout of the first message, with a : prompt if message overflows certain amount of output. Hitting any key will cause it to continue to display more of the message, etc., until you read the end of it. Or you can scroll with your mouse/touchpad. You may be able to hit q to abort viewing the message (I can't test that just now, but try it).To delete all messages, you'd use command d *. To delete the second message, you'd use d 2, and so on. Use them at the mail ? prompt.
    – inspirednz
    May 30, 2017 at 0:22
  • 1
    You can also delete a range of messages, for example: d 1-15 May 8, 2018 at 15:15
  • For me the terminal message resulted out of an issue issue with one of my cron job scripts - errors during execution of cron jobs seem to be automatically posted to the local mail system. Jan 12, 2021 at 15:20
66

Probably it is some message from your system.

Type in terminal:

man mail

, and see how can you get this message from your system.

4
  • which email address is this using? Sep 16, 2015 at 3:09
  • 4
    and then type "d *" to erase all messages Mar 20, 2017 at 12:23
  • 9
    Accidentally emptying the /var/mail/<your-username> upon a mail arrival (which is still unread) can trigger You have mail every time you open a new tab in Terminal (which happened to me once). To solve this problem, the file is needed to be removed (ie. sudo rm /var/mail/<your-username>). Oct 6, 2017 at 2:10
  • 6
    This does not answer the question.
    – minatverma
    Apr 4, 2019 at 13:53
60

If you don't want the hassle of using mail, you can read the mail with

cat /var/mail/<username>

and delete the mail with

sudo rm /var/mail/<username>
4
  • can you tell me which email address is registered in /var/mail/ How would i check it? Sep 16, 2015 at 3:09
  • @androidplusios.design The email address is your user name on the system. The emails are the ones sent to you by the system. You may also be an alias for other users on the system, and thus receive their emails. See /etc/aliases. For more information, check out What is the “You have new mail” message in Linux/UNIX?.
    – kba
    Sep 16, 2015 at 20:50
  • This was the only answer here that actually worked for me, cheers! Feb 7, 2017 at 11:48
  • will the mail be automatically removed after I read?
    – Alex
    Aug 21, 2020 at 7:37
13

It means that a process or script you have created is sending mail to an account on your local machine (for example, a mail server running on localhost application).

Manage this mail with these commands:

t <message list>        type messages
n                       goto and type next message
e <message list>        edit messages
f <message list>        give head lines of messages
d <message list>        delete messages
s <message list>        file append messages to file
u <message list>        undelete messages
R <message list>        reply to message senders
r <message list>        reply to message senders and all recipients
pre <message list>      make messages go back to /var/mail
m <user list>           mail to specific users
q                       quit, saving unresolved messages in mbox
x                       quit, do not remove system mailbox
h                       print out active message headers
!                       shell escape
cd [directory]          chdir to directory or home if none given

A consists of integers, ranges of same, or user names separated by spaces. If omitted, Mail uses the last message typed.

A consists of user names or aliases separated by spaces. Aliases are defined in .mailrc in your home directory.

11

As inspiredlife explained, you can figure out whats happening using mail command.

If you don't want to delete bunch of unrelated / auto-generated messages one by one (like me), simply run the command below to get rid of all messages:

echo -n > /var/mail/yourusername
0

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