[solved] How To Delete Mail from Terminal in macOS

Written by  Thursday, 12 October 2017 14:46

If you show message in terminal “You have mail” you can delete all messages

sudo rm /var/mail/<your-username>

 If you want send mail via terminal use commands:

mail -s "hello" "example@example.com" <<EOF
hello
world
EOF

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.

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

Use the 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. You'll see 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.

849 Read Last modified on Sunday, 22 October 2017

Related items

  • How to change screenshot format png → jpg
    in Mac

    To save screenshots in JPG, execute the following commands in the terminal:

    defaults write com.apple.screencapture type jpg;killall SystemUIServer

    macOS also support: tiff, pdf, bmp & pict.

  • Как повысить свою эффективность в macOS можно с помощью режима «единственного окна»?
    in Mac

    В macOS есть специальный режим, который позволяет задействовать одновременно лишь одно окно. Все остальные программы при переключении будут просто скрыты.

    defaults write com.apple.dock single-app -bool true; killall Dock

    Чтобы вернуть настройки назад, нужно поменять true на false командой:

    defaults write com.apple.dock single-app -bool false; killall Dock
  • Launch Sublime Text 3 from the command line & simlink to Subl
    in Mac

    These instructions assume you’re using the Terminal app out of the box, without ZSH or any fancy prompts like that. I trust you will be able to adapt these instructions yourself if you do.

    Step 1 : Create a symlink called sublime

    sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/sublime

    Step 2 : Check that your system profile can find the symlink you just created.

    open ~/.bash_profile

    Step 3 : Add both these lines & then save the file :

    alias subl="open -a /Applications/Sublime\ Text.app"
    
    export PATH=/usr/local/bin:$PATH

    Step 4 : Reload your bash_profile :

    source ~/.bash_profile

    Done ! You can now navigate to any of your code/script folders in Terminal and open them in Sublime with the following commands :

    subl .
    subl .zshrc
  • How to Stop .DS_Store File Creation on Network Volumes in Mac OS X
    in Mac

    To disable the creation of .ds_store files, launch the Terminal application from /Applications/Utilities/ and enter the following command string exactly:

    defaults write com.apple.desktopservices DSDontWriteNetworkStores true

    Reboot the Mac for changes to take full effect.

  • Customize OS X's Login Screen with Any Logo You Want
    in Mac

    The login screen on your Mac is perfectly functional as it is, but if you want to spice it up a little bit, blogger Jacob Salmela shows you how to customize the login screen with a logo of your choosing.

    If you don't want to install a whole program just for a simple tweak it's easy to do manually. All you need is a PNG that's 428 X 248. Then, you'll need to save it as four different files.

    Here's instructions:

    You need four copies of this file, and they need to be named:

    • apple.png
    • apple@2x.png
    • apple_s1.png
    • apple_s1@2x.png

    Once they are named correctly, just drag them into the following path:

    /System/Library/PrivateFrameworks/LoginUIKit.framework/Versions/A/Frameworks/LoginUICore.framework/Resources/

    and then choose to replace all of them.

    That's it, log out, and you should see your new logo. Head over to Salmela's site for a few sample images and instructions for making your own.