Bash: Send HTML Email from Linux Command Line

I’m trying to send an HTML formatted email from Linux Command line. Previously, I use mailx to send the email, but it’s only allow us to send plain text email. Luckily, I came across to ‘sendmail’. After testing couple of time, I’m finally able to send HTML formatted email. The code as follow:
(cat <<EOCAT
Subject: Title of the email
MIME-Version: 1.0
Content-Type: text/html
Content-Disposition: inline
EOCAT
cat htmlfile.html) | sendmail toemail@hollyghozi.com

As you see in my code above, there’re two parts of the email that I combine into one and send using ‘sendmail’.
- Header: the first ‘cat’
- Body: the second ‘cat’ is reading ordinary HTML file
and both redirect to sendmail that will send an HTML to recipient.

You can leave a response, or trackback from your own site.
  • Brett

    This was very very helpful. I have been looking for this solution for 2 hours on the web and your solution is the only one that is working. Thanks!!!

  • Rupeni

    Thanks.. just what i needed.. worked perfectly!!

  • markinsonmarshal

    THis is a very very essential blog for me it helped me a lot i was in search of it that how to Send HTML Email from Linux Command Line here i got it thank you… ITIL V3

  • markinsonmarshal

    THis is a very very essential blog for me it helped me a lot i was in search of it that how to Send HTML Email from Linux Command Line here i got it thank you… ITIL V3

  • Frobroj

    Great little script!! I tried some nasty massive perl scripts but this one works so much better.

  • http://www.bspmedia.fi Pauli Tuominen

    Thanks, very nice and simple solution.

Subscribe to RSS Feed Follow me on Twitter!