Mail command line linux
The mail
command in Linux is a simple command-line email client that allows you to send and receive email messages. Here are some basic commands and options:
Sending an email
mail -s "Subject" [email protected]
: Send an email with a subject and body.mail -s "Subject" [email protected] < message.txt
: Send an email with a subject and body from a file.
Receiving email
mail
: Check for new email and display the list of messages.mail -f
: Check for new email and display the list of messages, including deleted messages.mail -f -d
: Check for new email and display the list of messages, including deleted messages, and delete them.
Managing email
mail -d
: Delete a message.mail -r
: Reply to a message.mail -f
: Forward a message.mail -s
: Save a message to a file.
Options
-s
: Set the subject of the email.-c
: Set the from address of the email.-b
: Set the body of the email.-f
: Check for new email and display the list of messages.-d
: Delete a message.-r
: Reply to a message.-f
: Forward a message.-s
: Save a message to a file.
Examples
- Send an email to
[email protected]
with the subject "Hello" and body "Hello, how are you?":mail -s "Hello" [email protected]
- Send an email to
[email protected]
with the subject "Hello" and body from a filemessage.txt
:mail -s "Hello" [email protected] < message.txt
- Check for new email and display the list of messages:
mail
- Delete a message:
mail -d <message_number>
- Reply to a message:
mail -r <message_number>
- Forward a message:
mail -f <message_number>
- Save a message to a file:
mail -s <message_number> > message.txt
Note: The
mail
command is a simple command-line email client and does not support many features that are available in modern email clients, such as attachments, HTML emails, and encryption.