To redirect the output of a command to mail and also add some text to the body of that message, wrap multiple commands in parentheses like so:
(echo "Here's the text you want to add"; ls -l /)|mail email@example.com
This makes your text appear above the output of the ls command in this case. Separate the commands with semi-colons or put the commands on separate lines.
(echo "Have look at these great files"
>ls -l /)|mail firstname.lastname@example.org
Here's another example that adds a subject line to the message:
(echo "Subject: Nifty tricks you can do with email"; echo "Here's
>body of the message. Note the backslash at the end of the lines. \
>While you can just hit Enter and continue creating text for the body \
>of the message, the text will wrap at that point; the backslashes \
>prevent that, which may or may not be what you want."; ls -l /)| mail email@example.com
In the above example, backslashes keep newlines from appearing in the message when you hit the Enter key. When I got the message in Outlook the text was wrapped in the proper places. You could also just hit Enter right after 'echo " '. For example:
(echo "Subject: Nifty email tricks"; echo "
>This is the body of the message. The advantage of doing it this way
>is that the message will be formatted roughly the same as you type
>it, with the recipient seeing the wrap in the same place you put it.")|
Note in the above example that the opening quote mark after the 'echo' must be on the same line as the word 'echo'. In other words,
You may also want to put the closing quote on its own separate line
to provide a blank line between the message and the command output that