The following one-liner produces an HTML file named email.html
:
diff file1 file2 | vim - +TOhtml '+w email.html' '+qall!'
You can now use Pekka’s code to send the email.
However, I believe in using the right tool for the right job – and VIM may not be the right tool here. Other highlighters exist and their use is more appropriate here.
For example, Pygments can be harnessed to produce the same result, much more efficiently and hassle-free:
diff -u report.log .report.log | pygmentize -l diff -f html > email.html
Notice that this produces only the actual text body, not the style sheet, nor the surrounding HTML scaffold. This must be added separately but that’s not difficult either. Here’s a complete bash script to produce a valid minimal HTML file:
echo '<!DOCTYPE html><html><head><title>No title</title><style>' > email.html
pygmentize -S default -f html >> email.html
echo '</style></head><body>' >> email.html
diff -u report.log .report.log | pygmentize -l diff -f html >> email.html
echo '</body></html>' >> email.html
EDIT In case that Pekka’s code didn’t work – as for me – because you don’t have the required versions of mail
and mutt
installed then you can use sendmail
as follows to send the HTML email:
( echo 'To: [email protected]'
echo 'Content-Type: text/html'
echo 'Subject: test'
echo ''
cat email.html ) | sendmail -t
It’s important to leave an empty line between the header and the body of the email. Also, notice that it’s of course unnecessary to create the temporary file email.html
. Just paste the rest of the commands into the right place above and delete the redirects to file.