To send the contents of a text file using the mail
command in Unix or Linux, you can use the following syntax:
mail -s "Subject" recipient@example.com < file.txt
This will send the contents of file.txt
as the body of the email, with the subject "Subject". You can replace recipient@example.com
with the email address of the recipient.
You can also specify multiple recipients by separating their email addresses with a comma:
mail -s "Subject" recipient1@example.com,recipient2@example.com < file.txt
If you want to include additional text in the body of the email, you can use the echo
command to create a message and pipe it to mail
:
echo "Additional text" | mail -s "Subject" recipient@example.com -A file.txt
This will include the contents of file.txt
as an attachment, and the text "Additional text" as the body of the email.
Note: The
apt-get
,yum
, etc.) or use a different command-line email client such asmutt
.