1

I'm trying to add an HTML part to an Email - which can be any type of MIME (probably mixed or alternative, we get it raw from GMail).
Here's how we currently do it:

email_copy = deepcopy(original_email)
if 'Content-Type' in original_email:
    original_email.replace_header('Content-Type', 'multipart/mixed')
else:
    original_email.add_header('Content-Type', 'multipart/mixed')
warning_part = [MIMEText(warning_html, 'html', 'UTF-8')]
original_email.set_payload(warning_part)
original_email.attach(email_copy)

The above snippet works well for GMail web client, GMail Android app, Outlook on Mac, etc. However, on some specific EMail clients we the email is displayed differently:

  • On Outlook App for Android, the body is missing and no attachments;
  • And on Outlook 2016 app on Windows 8.1, the body is missing but it appears as 2 attachments (text and html).

Now I came across this thread:
HTML-Email with inline attachments and non-inline attachments (@Renat Gilmanov)
And this one:
Mail multipart/alternative vs multipart/mixed (@Iain)

The first one relates to controlling whether images are displayed inline or as attachments. I tried to apply it to my case but I still get the same behavior. The second suggests a specific structure which I also couldn't make it work on my case.

What is the correct structure I should use in order to add an HTML prefix to the original message - so it will display uniformly on all the main EMail clients? P.S. I'm currently trying to avoid editing the original html part, but it's my last resort.

Any help would be much appreciated!

shachar0n
  • 162
  • 10
  • Does the library you are using support a reply/forward feature where you can add the additional content? – Iain Nov 21 '17 at 05:12
  • Here is a some java code doing a reply: https://www.dineshonjava.com/replying-email-in-java-mail-api/ it appears you are attaching the reply which I assume is not the same as a multipart. Can you write the email out and include that in your question? – Iain Nov 21 '17 at 05:18

0 Answers0