You have mail in the Mac Terminal

Posted in Mac on May 10, 2019 · 2 mins read
What can I do when my Mac terminal tells me "You have mail"?

If you do web development on your box and if you've ever developed in WordPress, on setup, you may recall you were prompted with an email account on creation.  If you develop something or if your site gets an error an email to admin will be sent out so if you entered a dummy email account your Mac will through a MAILER-DAEMON. If you've never removed the emails you will see You have mail in the terminal on startup but what can we do about it?

I wouldn't suggest ignoring the emails so we will discuss later on how to nuke them all at once but for now lets figure out how to read them. Type mail in the terminal and you should see several emails with a ? on a new line. To read the first message, at the ? type n to read that email, instead of seeing a ? you should see a : on the last line. This would indicate you're in the email so if you'd like to delete it now, at : type d for deletion.

If you didn't want to cycle through each one, in the terminal, you can output the contents of the emails to a text file with:

cat /var/mail/<username> >> Desktop/mail_result.txt

We use cat which concatenates and prints files; the mail instance, so you will need to change <username> and last we tell where we want the file and we want it on our desktop named mail_result.txt

When you find the text file on your desktop go through it to make sure you need to address any concerns or if you want to keep it for your records. If you'd like to keep the file or plan to create a daily mail review you can rename the file with today's date whatever dot text.

Back in the terminal let's navigate to mail to see what's up. Before we go to mail take note of a few other mail commands that work in terminal:

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

In terminal, type mail if you're not in mail already and you will be re-directed to your emails and you should see a ? mark on the very last line. If you've outputted all the emails and are wanting to remove everything in mail try:

d *

and that will remove everything. After removing everything, on a new line you should see ?. To test to make sure you have deleted all emails at ? type q which means quit, and try mail. If all the emails were removed you should be returned No mail for &#60;username&#62;. If you are tired of typing you can close out terminal and re-open a new terminal window.

Help the site go ad free:
Storm Trooper