I want to use sendmail to send me stuff and want to do it in a oneliner.
echo "mail content" | sendmail emailataddres.com
Sends it without subject.
The subject line must come before the Mail content, so I am looking for something along the lines of:
echo "mail content" | prepend "Subject: All that matters" | sendmail emailataddres.com
sed and awk tend to be really awkward to use and remember.
EDIT:Just to clarify: echo "Mail content" is just an illustrating example. I need to be able to prepend stuff to stdout streams from any source. e.g.: ifconfig, zcat, etc..
echo -e "Subject: All that matters\nmail content"
? Or more platform agnostic:printf 'Subject: %s\n%s\n' "All that matters" "mail content"
. You could also write a small script that just takes the two string arguments to make an even simpler one-liner.prepend
do? In order to know how to prepend something, you have to wait until the upstream command (e.g.echo
) sends the EOF, so that you can insert your data ahead of it in the stream before passing it to stdout to get piped to sendmail. Sounds like a task for a shortish Ruby or Python script.mail
command (sometimes called bsdmail) instead ofsendmail
directly.mail
takes an optional-s subject
option, e.g.:ifconfig -a | mail -s 'Current ifconfig output' [email protected]