When I open up my terminal it says "you have mail", anyone has any idea of why? I am running OS X, but since it too is based on Unix and relies on files such as bashrc, bash_profile etc. I thought somebody here might know, and I'm not sure it's a platform specific problem!
It sounds like something has sent mail on (and to) the machine using the local mail exchanger. Most likely the email is an automated message from some installed package. Once you log in, type
? to find out what the commands are.) Once you've read or deleted any unread mail, you won't see the "You have mail" message again until/unless something else sends mail in the same way. Odds are once you know what's sending you the mail, you can find a configuration option to change where it sends it to.
It is a "platform specific problem" :-)
Mac OS X uses as default shell the BASH like many other Un*x/Linux systems.
Mail from your system is stored in mailbox for your user, often located in
Because sometimes your mailbox will contain important messages (a failed cronjob task, etc.) you don't to check it every time by yourself.
The BASH (and many other shells) have a feature called mailcheck, which outputs your message the first time you open your terminal.
$MAILCHECK is an environment variable which contains the seconds when its time to check for new mail. Mail is also checked before displaying the primary prompt.
See more in
man bash - Bash Variables.
To prevent the checks for new mail, you can simply unset $MAILCHECK. The right place for this is your .bashrc file, which will be read when you open up a shell. Its in your user home directory.
Append to ~/.bashrc:
to disable the message.
Of course it is also possible to simply delete the mails like T.J. Crowder mentioned :-)
I was also having this issue of "You have mail" coming up every time I started Terminal. It was caused by a locally hosted website sending mail (Wordpress, in my case).
To view the messages
You can access the mail by simply using the command
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
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
If you want to jump to the end of the message, use the
If you want to abort viewing the message, use
To view the next message in the queue use
... 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
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
3, for instance, will show you the content of the third message (if there are that many in there).
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),
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
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):
And, if you wish to delete the emails all in one hit, use this command
sudo rm /var/mail/<username>
Source of messages
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.
Deleting all messages without further ado
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
sudo rm /var/mail/YOURUSERNAME
(Originally posted by me here)