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.
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.
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 ...
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">"