Related Entries

India PyCon 2009
Quick wallpaper changer
Load testing with Grinder
Adding namespace to XML
Opera RSS to OPML

« 2003 BMW Z4
» Joy of Python: Self documenting code

CompMail: Send HTML mail

At times you are required to send HTML mail with embedded images programatically. Here's my effort to do it in Python.

I had to do some research on sending rich emails(personally, I think rich emails are annoying) that are HTML encoded, with colors, styles and embedded images. After some looking around, I came up with a python script that parses an HTML file, rewrites it with proper MIME headers, packs it as a multi-part message and mails it.

A tar archive of the script and libraries are available for download (73Kb). It is not perfect and certainly has scope for improvement. However, I’m making it available for download because I think people might find it useful, to extend it to their own needs. You can untar it by tar zxvf compmail-1.0.tgz. This will extract it to a folder named compmail.

Works from the following:
Embedded images appear broken in:

These must be bugs with the script since both Yahoo mail and Evolution can display inline images. I’ll solve that later.

Interesting reference: Survey of HTML E-mail clients.

Limitations and Scope for improvement:
  • compmail.py doesn’t take any arguments. It is easy to add that.
  • MyHTMLProcessor.py assumes all embedded images are in the same folder. This can be augmented to parse more intelligently for getting images in other folders.
  • Email clients that don’t understand inline embedding are not given a text version. Need to read more about mail specs on the formatting required. At the moment, this is for a limited audience, so it works for me. Please do send your suggestions to me.
  1. Today, Barry Warsaw has released an "email" package for Python, which will be included in Python 2.3. Check it out at http://sf.net/projects/mimelib

    Posted by: Babu on September 11, 2002 06:33 AM
  2. I'm trying to make contact with Cody who was helping me with implementing use of the Japanese language on the internet. Thanks.

    Posted by: carl sycks on September 18, 2002 05:18 PM
  3. Hmmm... The header of all these pages probably would've made it clear that my name is not Cody. Anyway, I'm not Cody and I've no idea about Japanese language.

    I'm actually inclined to think that this is another way to get some email addresses for spamming - may be I'm just being paranoid.

    Posted by: Babu on September 19, 2002 08:39 AM
  4. we are writing our own email web based client .We are not able to display HTML messages properly if it has inline images.one thing is to replace all the cid tags with proper image locations.is there any other way to improve performance

    Posted by: anandh on November 28, 2002 08:25 AM
  5. Want to have more visitors just visit this site:

    Posted by: Amr on June 12, 2003 01:47 PM