Bash mail multiline body example

Here is an example of how to send a multi-line body in a mail using bash:

echo "Subject: This is the subject of the email" | 
  mail -s "" -c "From: [email protected]" -c "To: [email protected]" -b -

In this example, the -b - option tells mail to read the body of the email from standard input. The echo command is used to generate the body of the email, which is a multi-line string.

Here's a breakdown of the options used:

You can also use echo with the -e option to enable interpretation of backslashes (\) as escape characters, which allows you to include newline characters (\n) in the body of the email:

echo -e "This is the first line of the email.\nThis is the second line of the email." | 
  mail -s "" -c "From: [email protected]" -c "To: [email protected]" -b -

This will send an email with a multi-line body:

Subject: This is the subject of the email
This is the first line of the email.
This is the second line of the email.