title: Multipart/mixed email attachments not showing up, but only in Windows 10 Mail
body: <p>Having a weird problem with emails I am sending out via Python <code>email</code> / <code>smtplib</code>.</p>
  
  <p>I am attempting to compose an email with:</p>
  
  <ul>
  <li>Alternatives of plain-text and HTML message bodies</li>
  <li>An image embedded inline in the HTML body</li>
  <li>A separate non-inline attachment</li>
  </ul>
  
  <p>The MIME structure is setup like this:</p>
  
  <pre><code>multipart/mixed
      multipart/alternative
          text/plain
          multipart/related
              text/html
              image/png - inline
      application/pdf - attachment
  </code></pre>
  
  <p>This seems to work fine on every mail client I've tested {BlueMail on Android, iOS mail client, Roundcube} <strong>except</strong> for the Windows 10 mail client. For some reason, the Windows 10 built-in mail client seems to show the inline image just fine, but shows no trace of the other attachment. </p>
  
  <p>The limited information I have been able to find on the internet points to this being a bug with the Windows 10 mail client, but I have personally received other emails in this client with both inline and attached attachments, which are displayed just fine - so there obviously is some sort of workaround / alternative message structure that works. </p>
  
  <p>My question is thus: <em>How can I format this message differently so that it will show up properly in all relevant mail clients?</em></p>
  
  <p>I am composing the email like this, in Python:</p>
  
  <pre><code>message = MIMEMultipart("mixed")
  message["From"] = ...
  .
  .
  .
  bodyText = "..."
  bodyHTML = "..."
  mailFrom = "..."
  targetEmail = "..."
  imageContent = ...
  
  messageBody = MIMEMultipart("alternative")
  messageBody.attach(MIMEText(bodyText, "plain"))
  
  messageBodyHTML = MIMEMultipart("related")
  messageBodyHTML.attach(MIMEText(bodyHTML, "html"))
  messageImage = MIMEImage(imageContent)
  messageImage.add_header("Content-Disposition", 'inline; filename="..."')
  messageImage.add_header("Content-ID", "&lt;id used in html body&gt;")
  messageBodyHTML.attach(messageImage)
  
  messageBody.attach(messageBodyHTML)
  
  message.attach(messageBody)
  
  
  attachment = MIMEApplication(fileContent, Name=fileName)
  attachment.add_header("Content-Disposition", 'attachment; filename="..."')
  message.attach(attachment)
  
  
  self.smtplibSession.sendmail(mailSource, targetEmail, message.as_string())
  </code></pre>
  
  <p><strong>Update:</strong> Here's the message data from Windows 10 mail (as output via the "save" feature - there's no way to view the original message raw data that I can find...)</p>
  
  <pre><code>MIME-Version: 1.0
  Date: Thu, 30 May 2019 17:45:28 +0200
  From: xxxxx &lt;xxxxx&gt;
  Subject: xxxxx
  Thread-Topic: xxxxx
  To: "xxxxx" &lt;xxxxx&gt;
  Content-Type: multipart/related;
      boundary="_5D6C043C-FD42-42F9-B0E0-841DBFBA96D5_"
  
  --_5D6C043C-FD42-42F9-B0E0-841DBFBA96D5_
  Content-Transfer-Encoding: quoted-printable
  Content-Type: text/html; charset="utf-8"
  
  &lt;center&gt;&lt;img src=3D"cid:embedded-image" alt=...
  
  --_5D6C043C-FD42-42F9-B0E0-841DBFBA96D5_
  Content-Type: image/png; name="embedded-image.png"
  Content-ID: &lt;embedded-image&gt;
  Content-Transfer-Encoding: base64
  Content-Disposition: inline; filename="embedded-image.png"
  
  iVBORw0KGgoAAAAN...
  
  --_5D6C043C-FD42-42F9-B0E0-841DBFBA96D5_--
  </code></pre>
  
  <p>I'm not sure if this is a result of saving the email from the app, or this is what the app is actually storing, but it seems that the Windows 10 Mail app is cutting out everything outside the <code>multipart/related</code> stanza - that is, it's only taking the chosen <code>alternative</code> and not storing anything else.</p>
  
  <p>For comparison, I've found and exported an email that displayed properly, with an image, html, and attachment, but the format seems to be a lot simpler - that email consisted only of a <code>multipart/mixed</code> layer with <code>text/html</code> and an <code>application/pdf</code> attachment. That email used an external image referenced in the HTML, instead of embedding it in the message - I would like to avoid hosting the images in each email externally.</p>