How to Send The Content Of a Text File Using mail Command In Unix / Linux

How to Send The Content Of a Text File Using mail Command In Unix / Linux

To send the contents of a text file using the mail command in Unix or Linux, you can use the following syntax:

refer t‮‬o:lautturi.com
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 mail command is not installed by default on all Linux distributions. If it is not available on your system, you can install it using your distribution's package manager (e.g. apt-get, yum, etc.) or use a different command-line email client such as mutt.

Created Time:2017-10-29 22:08:35  Author:lautturi