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.
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.
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:If you want to send email with image as attachment (in my situation it was image that has been caught directly from form, after its saving) you can use the following code as example:
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 ...
I achieved what op is asking for using django's mailing system. Upsides it that it'll use django settings for mailing (including a different subsystem for testing, etc. I also use mailhogs during development). It's also quite a bit higher level:
logo_data
is a helper function that attaches the logo (the image I wanted to attach in this case):I have tried the below code and it worked.
Code: