How to send (encode) emojis (or any foreign language text) in the Subject of Gmail API?

Viewed 383

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;
};
0 Answers
Related