Django: How to send HTML emails with embedded images

前端 未结 5 1750
心在旅途
心在旅途 2020-12-03 03:18

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 ap

5条回答
  •  独厮守ぢ
    2020-12-03 03:48

    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': ''} 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 = 'Some HTML text and an image: '
    

提交回复
热议问题