Mail Command in Unix/Linux

The mail command in unix is used to send the emails, receive the emails, delete the emails, etc..
The syntax for the mail command is

The options are
  • -a:Append given header to the message being sent.
  • -b: Send blind copies of the mail to the list of users.
  • -c:Send carbon copies of the mail to the list of users. 
  • -e:Return true if mail exists.
  • -E:Execute COMMAND
  • -F:Save messages according to sender.
  • -f:Read mail from mailbox called file.
  • -H:Write a header summary and exit.
  • -p:Print all mail to standard output.
  • -s:Send a message with a Subject of SUBJ.
  • -t:Precede message by a list of addresses.
  • -v:Verbose mode. Delivery details are displayed on the terminal.
Examples of mail command
  • Sending mail to user
                                     mail -s "subject"  aa@example.com                        
  • Specifying body in mail
                          cat body.txt |  mail -s "subject"  aa@example.com             
  • Send by using cc and bcc option
      mail - s "subject" -c "aa@example.com"  -b "bb@example.com"  "dd@example.com"   
  • View received mail by using below command
  • Delete read email by using below command 
Type -d and press enter, it will delete read emails
Powered by Blogger.