0
votes

I'm using GMail API to send a MIME email. The text part of the email always gets regenerated from the HTML part.

I have tried various variations in MIME and how I structure the headers. Another man reported the same problem a few years back:

Gmail API replaces text/plain alternative body part with automatically generated one from HTML

The message shows correctly in GMail interface "Sent" items, if I view the original of the message. However, the message arrives at the destination with text part replaced with HTML part. I tested it with several destinations, including Yahoo Mail.

The relevant part of the input multipart message is:

--0000000000d81f74059447a2ad02
Content-type: text/plain; charset=UTF-8

Hello plain text

--0000000000d81f74059447a2ad02
Content-type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<b>Hello html</b>

--0000000000d81f74059447a2ad02--

Viewing the raw message at the target (Yahoo Mail) shows this:

--00000000000046bd1105948482e9
Content-Type: multipart/alternative; boundary="00000000000046bd0e05948482e7"

--00000000000046bd0e05948482e7
Content-Type: text/plain; charset="UTF-8"

*Hello html*

--00000000000046bd0e05948482e7
Content-Type: text/html; charset="UTF-8"

<b>Hello html</b>

--00000000000046bd0e05948482e7--

Here's the full test case,

https://gist.github.com/borisreitman/448e2699c267221ebbf430b64346baaa

Notice that the text part now contains "Hello html" instead of the original "Hello plain text".

1
I found an open bug in GMail API reported back in 2016.issuetracker.google.com/issues/36760128Boris Reitman

1 Answers

0
votes

The proper syntax for the message composition is confusing

You need to past your plain text content BOTH in the text/plain and text/html part of the message.

Modify your code message body as following and it will work as a charm:

--0000000000d81f74059447a2ad02
Content-type: text/plain; charset=UTF-8

Hello plain text

*Hello html*

--0000000000d81f74059447a2ad02
Content-type: text/html; charset=UTF-8

<div dir="ltr">Hello plain text<br><div><br></div><div><b>Hello html</b><br></div></div>

--0000000000d81f74059447a2ad02--