2

I'm using the Gmail API in REACT NATIVE to send mails and using "js-base64" lib to encode the MIME message before sending out through the api. Everything works fine but the emoji's in the Subject part isn't decoded the right way

Subject text works fine but the emoji's are decoded the wrong way

(Edited) This is the gmail send mail api call

const sendEmail = async (message: ISendMessage) => {
  const data = JSON.stringify({
    raw: getMessageMime(message),
    threadId: message.threadId,
  });
  const response = await G_POST(data, SEND_EMAIL_URL, 'application/json');
  return response.data;
};

const getMessageMime = (message) => {
  let mail = [
    'Content-Type: multipart/alternative; boundary="foo_bar_baz"\r\n',
    'MIME-Version: 1.0\r\n',
    'To:' + message.to + '\r\n',
    'From:' + message.from + '\r\n',
    'Cc: ' + message.cc + '\r\n',
    'Bcc: ' + message.bcc + '\r\n',
    'References:' + message.inReplyTo + '\r\n',
    'In-Reply-To:' + message.inReplyTo + '\r\n',
    'Subject: ' + message.subject + '\r\n\r\n',
    '--foo_bar_baz\r\n',
    'Content-Type: text/plain; charset="UTF-8"\r\n',
    'MIME-Version: 1.0\r\n',
    'Content-Transfer-Encoding: 7bit\r\n\r\n',
    message.message + '\n\r\n',
    '--foo_bar_baz--',
  ].join('');

  mail = btoa(mail);
  return mail;
};
Praneeth G
  • 41
  • 4
  • 😂😂😠these is how most of the emoji's get decoded to – Praneeth G May 20 '20 at 14:47
  • Hi @PraneethG! Could you please share your code so we all can take a look? Take this opportunity to surf the [tour](https://stackoverflow.com/tour) and learn [where to start](https://softwareengineering.meta.stackexchange.com/questions/6366/), [how to ask](https://stackoverflow.com/questions/how-to-ask) questions, how can you [format code](https://meta.stackexchange.com/questions/22186) and share a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) with us so we can help you better. – Jacques-Guzel Heron May 21 '20 at 10:45
  • Please show your actual code. What you are seeing is what happens when charset mismatches occur. For instance, when the emoji is encoded in UTF-8 and then misinterpretted as Latin-1 – Remy Lebeau May 21 '20 at 22:20
  • @RemyLebeau I've updated with the code, thanks – Praneeth G May 25 '20 at 16:14
  • Thank you for sharing the code @PraneethG! After studying the situation I have some questions. Gmail renders the emojis differently depending on the place; on the subject it uses the navigator native rendering and in the corpus it uses a different palette. To discard a navigator problem, please send an email with the emoji string `⛎️‍♂️♐` in the subject and in the corpus. To prevent any encoding mismatch, please copy and paste the emoji string instead of selecting them from the emoji menu. – Jacques-Guzel Heron May 27 '20 at 07:41
  • Does this answer your question? [Emoji is not rendered in the subject of gmail](https://stackoverflow.com/questions/64947400/emoji-is-not-rendered-in-the-subject-of-gmail) – user835611 Dec 12 '20 at 10:05
  • did you resolve this issue? Can you please add an answer to this? – Rakmo Aug 25 '22 at 18:34

0 Answers0