主题 gmail 中的特殊字符 api node.js

Special characters in subject gmail api node.js

我正在尝试使用 gmail rest api 发送电子邮件,一切正常,除非我尝试在主题中使用特殊字符。我尝试过不同的解决方案,例如:

`Subject: =?utf-8?B?${email.subject.toString('base64')}?=\n\n` +

示例 1 的结果

example2

`Subject: =?iso-8859-1?Q? ${quotedPrintable.encode(utf8.encode(email.subject))}?=\n\n` +

示例 2 的结果

这是实际代码:

const mail = Buffer.from(`From: ${from}\n` +
    'Content-Type: text/html; charset=UTF-8\n' +
    `To: ${to}\n` +
    `Cc: ${cc}\n` +
    `Bcc: ${bcc}\n` +
    `Subject: =?utf-8?B?${email.subject.toString('base64')}?=\n\n` +
    `${$.html()}`)
    .toString('base64').replace(/\+/g, '-').replace(/\//g, '_');
  const response = await axios.post(`https://www.googleapis.com/gmail/v1/users/${from}/messages/send?access_token=${token}`, {
    raw: mail,
  });

这是我要发送的主题样本:

1 - = live unbound!!   que viva España

我找到了这个问题的解决方案

`Subject: =?UTF-8?Q?${quotedPrintable.encode(utf8.encode(email.subject))}?=\n\n`