Bash mail from

The mail command in bash!

The mail command is used to send and receive email messages from the command line. Here are some basic examples of how to use it:

Sending an email

To send an email using mail, you can use the following syntax:

mail -s "Subject" [email protected]

Replace Subject with the subject of your email, and [email protected] with the email address of the recipient.

You will then be prompted to enter the body of the email. You can type in the message, and then press Ctrl+D to send the email.

Receiving email

To receive email using mail, you can use the following syntax:

mail

This will display a list of your email messages. You can then use the following commands to manage your email:

Other options

Here are some other options you can use with the mail command:

Example usage

Here's an example of how you might use the mail command to send an email:

$ mail -s "Hello from bash!" [email protected]
Subject: Hello from bash!

Hello,

This is a test email sent from the bash shell.

Best,
Your Name

$ Ctrl+D

And here's an example of how you might use the mail command to receive email:

$ mail
Mail version 8.1.2 02/02/2005. Type? for help.
"/var/mail/username": 2 messages in body of this mail.

1  (1/2)  From  [email protected]  Tue Feb  2 14:30:00 2023
   Subject: Test email

2  (2/2)  From  [email protected]  Tue Feb  2 14:35:00 2023
   Subject: Another test email

?  to delete
d  to save and delete
m  to reply
r  to reply all
s  to save and return
?  to help

Enter command: