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.
  • Thanks, very nice and simple solution.
  • Frobroj
    Great little script!! I tried some nasty massive perl scripts but this one works so much better.
  • 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
  • Rupeni
    Thanks.. just what i needed.. worked perfectly!!
  • 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!!!
blog comments powered by Disqus
Subscribe to RSS Feed Follow me on Twitter!