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:
1
to read the first message2
to read the second messaged
to delete a messager
to reply to a messageq
to quit
Other options
Here are some other options you can use with the mail
command:
-c
to compose a new email message-f
to specify a file containing the email message-s
to specify the subject of the email message-a
to specify an attachment to the email message
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: