Just converted my GCP cloud Java app to send email messages to Google Workspace via Gmail API rather than sendmail. In the past I was able to format HTML UTF-8 and send extended characters, but now it seems google is replacing them with "?" literals once it receives the message. I have verified that prior to sending using Gmail API the characters are there, and verified that after the message is sent through Gmail and distributed to the client, the raw message text contains "?" instead of the original characters.
In my HTML message body I am using this meta tag:
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head>
The special characters include the alternative form for double-open quotes, double-close quotes, and stylized apostrophe:
<p>“Must’ve been fate, you and I.”</p>
Gmail API is replacing this with:
<p>?Must?ve been fate, you and I.?</p>
and it shows that way on all devices/mail clients because the "?" are now literal.
Java code that calls the Gmail API:
MimeMessage email = new MimeMessage(session);...email.setSubject(subject);email.setContent(htmlBodyText, "text/html");...ByteArrayOutputStream buffer = new ByteArrayOutputStream();email.writeTo(buffer);byte[] rawMessageBytes = buffer.toByteArray();String encodedEmail = Base64.encodeBase64URLSafeString(rawMessageBytes);Message message = new Message();message.setRaw(encodedEmail);...message = service.users().messages().send(myEmailAddress, message).execute();
Suggestions?
UPDATE: Adding the raw message source received by Thunderbird mail client for reference:
--0000000000002d8e4006346347a4Content-Type: text/html; charset="UTF-8"Content-Transfer-Encoding: quoted-printable<html><head> =20<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DUTF-8"=></head><body><div style=3D"padding:10px 15% 10px 15%;text-align:center;font-family:&#=39;Open Sans',Helvetica,Arial,sans-serif"> =20<div style=3D"width:100%;height:100px;background-color:black;margin-bott=om:20px;color:white;text-align:center;vertical-align:bottom;display:inline-=block;font-family:WeezerFont,Verdana,'Open Sans',Helvetica,Arial,sa=ns-serif;padding-top:10px;padding-bottom:10px;padding-top:10px"></div>=20<div style=3D"width:100%;height:100px;margin-bottom:20px;text-align:c=enter;vertical-align:bottom;display:inline-block;font-family:WeezerFont,Ver=dana,'Open Sans',Helvetica,Arial,sans-serif"></div><h2>Test Email Message</h2><p>?Must?ve been fate, you and I.?</p> =20<p> =20 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin con=sectetur mauris ac placerat consequat. Nulla dictum libero mi, ac tempor neque tincidunt vitae. Quisque sagitti=s dignissim erat non accumsan. Cras eget mauris orci. Proin sed ullamcorper metus. Donec ut turpis vitae er=os consequat egestas vitae ac mi. Duis tristique ipsum dictum diam imperdiet, tempus sagittis ante ultric=ies. In hac habitasse platea dictumst. Sed consectetur imperdiet turpis, vel consequat ex malesuada vel. Inte=ger ut mauris metus. Phasellus eleifend sollicitudin est et posuere. Nam cursus sapien quis erat tincidunt= pharetra. Praesent id neque ut felis scelerisque aliquam. Nunc gravida ac erat quis dignissim. </p></div>=20</body></html>--0000000000002d8e4006346347a4--