The requirement is that this be an executable script which can take any number of command-line arguments describing email headers, and which receives the body of an email on STDIN. I think this can all be done via pipes but I'm not entirely sure how - the trick is that the output of the program over STDOUT needs to be the concatenation of formatted command-line arguments plus the contents of STDIN. I had difficulty figuring out how to have two different commands both send output, in order, to the STDIN of `msmtp -t`. msmtp is configured to send email via a Google Apps account.
Here's what I'm using at the moment. It works but I think it could be more elegant and UNIXY without the temporary file.
#!/bin/sh
T=`/opt/bin/mktemp` # create a temporary file
echo -e "From:$1\nTo:$2\nSubject:$3\n" > $T # format command-line args into the file
cat <&0 >>$T # append STDIN to the file
msmtp -t <$T # mail the file (-t parses the smtp recipient from the email headers)
rm $T # delete the file
# used as follows:
#/usr/local/bin/minimail "sender@example.com" "recipient@example.com" "Subject of the Email" <body.txt
Any ideas?