Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7778353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:22:35+00:00 2026-06-01T18:22:35+00:00

I’m trying to create an email in Django with inline images. msg = EmailMultiAlternatives(…)

  • 0

I’m trying to create an email in Django with inline images.

msg = EmailMultiAlternatives(...)
image_file = open('file_path', 'rb') 
img = MIMEImage(img_data)
image_file.close()
img.add_header('Content-ID', '<image1>') 
img.add_header('Content-Disposition', 'inline')
msg.attach(img)
msg.send()

And in the template I would reference it like so:

<img src="cid:image1" />

This works fine in web browsers, outlook, thunderbird … all except for the apple mail client on OSX, iPad and iPhone. The images are displayed twice. They are placed inline correctly but they are also attached to the bottom of the email. My question is, how do I get rid of the images at the bottom? or should I approach images in emails differently.

References:
http://djangosnippets.org/snippets/1507/
Django: How to send HTML emails with embedded images
creating a MIME email template with images to send with python / django

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:22:36+00:00Added an answer on June 1, 2026 at 6:22 pm

    Different email clients choose to render multipart/mixed messages in different ways.

    Most clients choose to render each part (in a “multipart” message) inline – in the order they were added to the email. However, if an image is referred to in a text/html part, most clients don’t display that image again later on as part of the “inlining all parts” process.

    Apple Mail on OSX and iOS are different, in so far as they will display each part in a multipart/mixed message in the order they were included, regardless of any inner references between HTML and images. This results in your images being displayed once within your HTML, and again at the end of the message where they’ve been inlined automatically.

    The solution is to group your HTML and image assets into a single related part. i.e.:

    from django.core.mail import EmailMultiAlternatives
    from email.mime.image import MIMEImage
    from email.mime.multipart import MIMEMultipart
    from email.mime.text import MIMEText
    
    # HTML + image container 
    related = MIMEMultipart("related")
    
    # Add the HTML
    html = MIMEText('an image: <img src="cid:some_image"/>', "html")
    related.attach(html)
    
    # Add an image
    with open("icon.png", "rb") as handle:
        image = MIMEImage(handle.read())
    image.add_header("Content-ID", "<some_image>")
    image.add_header("Content-Disposition", "inline")
    related.attach(image)
    
    # top level container, defines plain text version
    email = EmailMultiAlternatives(subject="demo", body="plain text body",
                                   from_email="foo@example.com",
                                   to=["bar@example.com"])
    # add the HTML version
    email.attach(related)
    
    # Indicate that only one of the two types (text vs html) should be rendered
    email.mixed_subtype = "alternative"
    email.send()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.