Send HTML formatted mail from Unix using Sendmail

Contributor Icon Contributed by braindonor Date Icon November 11, 2004  
Tag Icon Tagged: UNIX

I have used this quite a bit and it works great for me. We’re on an HP box running Unix 11.11. You can embed javascripts, css, etc. Pretty cool stuff.


(
echo "From: you@your_company.com"
echo "To: you@your_company.com"
echo "MIME-Version: 1.0"
echo "Content-Type: multipart/mixed;"
echo ' boundary="PAA08673.1018277622/server.domain.com"'
echo "Subject: Test Message"
echo ""
echo "This is a MIME-encapsulated message"
echo ""
echo "--PAA08673.1018277622/server.domain.com"
echo "Content-Type: text/html"
echo ""
echo "

Test Message Body


"
echo "--PAA08673.1018277622/server.domain.com"
) | sendmail -t

Previous recipe | Next recipe |
 
  • braindonor
    The bottom half is actually HTML code...and the page seems to be displaying it as HTML, rather than just text. Change the "['s" to "<'s" and the "]'s" to ">'s" in the items below.

    echo "Content-Type: text/html"
    echo ""
    echo "[HTML]
    [BODY bgcolor=gray]
    [blockquote][font color=red]Test[/font] [font color=white]Message[/font] [font color=blue]Body[/font][/blockquote]
    [/body]
    [/html]"
    echo "--PAA08673.1018277622/server.domain.com"
    ) | sendmail -t

    Tom
  • Anonymous
    HTML email sucks!
  • cool
    HTML emails are cool!
  • Scrunchy
    Unlike that previous dweeb, I have some in-house uses for sending html-formatted mail from unix. Your solution works. Thanks very much.
  • oldUnixGuy
    I had your script modified and working for me in a few minutes. You saved me a fair amount of work. The HTML even displays corretly in Lotus Notes.

    I was looking for an alternate Unix mail client that would send HTML and while reading the Mutt docs noted that Mutt (like mail, mailx) is just a front end to sendmail. The light came on and I Googled for 'unix sendmail html' and your item came out at the top - right where it belongs.

    Just curious, is there any significance to the make up of the 'boundary' string? I plugged in my own server name and it worked. Does it just need to be a string that's random enough to be unique?
  • qmchenry
    I tried to find a definitive reference out there on the boundary string, but couldn't. In some IETF documents on MIME they use Content-Type: Multipart/Related; boundary=example-1. To my knowledge, it only needs to be unique within the email and probably only exists to allow multiple boundaries in an email.
  • Anonymous
    Hi

    I am new to this forum and have been battling with HTML formatting of e-mails. I have used the options on this thread, and they work OK, now I need to be able to send PDF attachments as well.

    I am currently using sendmail to send HTML formatted e-mails as follows :
    (cat body.txt) | sendmail -t recipient

    I use mail to send non-HTML formatted e-mail bodies with PDF attachments as follows :

    (cat body.txt;uuencode attach1.pdf attach1.pdf ;uuencode attach2.pdf attach2.pdf ) | mail -sSubject recipient

    sendmail works fine but will not send the attachment
    mail works fine but will not allow HTML formatted body.

    Please Help
blog comments powered by Disqus