views:

55

answers:

2

Hi all.

How can I send HTML emails with embedded images? How the HTML should link to the images? The images should be added as MultiPart email attach?

Any example is very appreciated.

A: 

http://djangosnippets.org/snippets/285/

You have to use MultiPart and cid:. It is almost always a bad idea to send html mails with images. It gives spam points to your mail and smtp server ...

iddqd
+1  A: 

Remember that django only offer wrappers for standard smtplib - I don't know if it will help, but try to look at this example: http://code.activestate.com/recipes/473810-send-an-html-email-with-embedded-image-and-plain-t/

So I guess you could use EmailMessage's header values to define this 'image1' - message header is a dict of values, so just add something like {'Content-ID': '<image1>'} to it.

Then attach the file to your email using attach(). After that you could use the code to generate the html message like this:

html_content = "<b>Some HTML text</b> and an image: <img src="cid:image1">"
bx2