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

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

example1

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

示例1的结果

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

example2

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

示例2的结果

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

这是实际的代码:

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
lkf1983 回答:主题gmail api node.js中的特殊字符

我已经找到了解决此问题的方法

`Subject: =?UTF-8?Q?${quotedPrintable.encode(utf8.encode(email.subject))}?=\n\n`
本文链接:https://www.f2er.com/3163853.html

大家都在问