Note that there are some explanatory texts on larger screens.

plurals
  1. POEmailMultiAlternatives adding a 3D when sending mail with image in django
    primarykey
    data
    text
    <p>I'm using the EmailMultiAlternatives class to send text and html mails with django. While testing with some dummy code, I wanted to add an image with some text.</p> <pre><code>msg = EmailMultiAlternatives('My subject','some text here', 'from@domain.com', ['to@my_domain.com']) msg.attach_alternative('&lt;p&gt;here is what I was talking about&lt;/p&gt; &lt;img src="logo.png" alt="logo_here" /&gt; &lt;div&gt;You see???&lt;/div&gt;', 'text/html') msg.attach_file('/var/my_site/static/images/logo.png') msg.send() </code></pre> <p>The problem is that on the email client the image is not displaying...</p> <p>Looking at the raw email, I found this:</p> <pre><code>--===============1013820581535380480== Content-Type: text/html; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable &lt;p&gt;here is what I was talking about&lt;/p&gt; &lt;img src=3D"logo.png" alt=3D"logo_h= ere" /&gt; &lt;div&gt;You see???&lt;/div&gt; --===============1013820581535380480==-- </code></pre> <p>Does anybody have an idea of what I'm doing wrong??</p> <p>Thanks!</p> <p>Edit: I could manage to embed an image into the html mail. It seems that the EmailMultiAlternatives has an attach method that can accept an MimeImage object. Actually it can accept anything that inherits from MimeBase. </p> <pre><code>fp = open('test.jpg', 'rb') msgImage = MIMEImage(fp.read()) fp.close() mimeImage = MimeImage(fp.read()) mimeImage.add_header('Content-ID', '&lt;logo.png&gt;') msg.attach(mimeImage) msg.send() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload