Javascript 如何使用谷歌应用程序脚本在电子邮件主题中使用表情符号?
我正在尝试使用谷歌应用程序脚本发送电子邮件Javascript 如何使用谷歌应用程序脚本在电子邮件主题中使用表情符号?,javascript,google-apps-script,google-sheets,gmail,Javascript,Google Apps Script,Google Sheets,Gmail,我正在尝试使用谷歌应用程序脚本发送电子邮件 //试试1 const subject='Hello World我相信你的目标如下 你想发送一封包含表情符号的gmail,比如・代码 您想知道使用GmailApp.sendmail而不使用MailApp.sendmail实现目标的方法 但是,当使用GmailApp.sendmail时,主题可以包括表情符号。但是表情符号不能在电子邮件正文中使用。所以我建议在这种情况下使用Gmail API。对于我的问题,作为另一个方向,在你的目标中,你能使用Gmai
//试试1
const subject='Hello World我相信你的目标如下
- 你想发送一封包含表情符号的gmail,比如
・使用Google Apps脚本在主题中编写>代码
- 您想知道使用
GmailApp.sendmail
而不使用MailApp.sendmail
实现目标的方法
- 但是,当使用
GmailApp.sendmail
时,主题可以包括表情符号。但是表情符号不能在电子邮件正文中使用。所以我建议在这种情况下使用Gmail API。对于我的问题,作为另一个方向,在你的目标中,你能使用Gmail API吗?
,你回答了是的,Gmail API会工作。
。所以我知道你的目标可以通过Gmail API实现
修改点:
- 在本例中,Gmail API与高级Google服务一起使用
- 而且,当您想要包含表情符号时,如
在电子邮件主题中,主题作为base64数据发送。・
- 当值include the emoji转换为base64数据时,在我的测试中,似乎需要将该值转换为base64作为UFT-8
- 我确认此解决方案也可用于
GmailApp.sendmail
main()
中设置变量,然后运行函数main()
参考资料:
- 相关线程
GmailApp.sendmail
而不使用MailApp.sendmail
实现目标的方法。通过这个,我重新打开了你的问题。嗨@Tanaike,你知道如何实现这个目标吗?谢谢你的回答。关于身体中的表情符号显示成功。
,我能问一下实现它的方法吗?因为当我测试你的脚本时,邮件正文中的表情符号无法正确显示。对此我深表歉意。试着看一看:例如,当HTML正文不包含表情符号,而您希望使用GmailApp.sendmail
仅在主题中包含表情符号时,我认为这是可以实现的。这个怎么样?嗨,塔奈克。伙计,非常感谢你。它工作得完美无缺。我只想再问一件事。当我们使用Gmail API时,我们可以发送多少封电子邮件,有没有配额?我知道使用GmailApp/MailApp,我们每天可以发送大约1000封电子邮件。@Ravgeet Dhillon感谢您的回复。我很高兴你的问题解决了。关于你的补充问题,这份官方文件有用吗?
function convert(toEmail, fromEmail, name, subject, textBody, htmlBody) {
const boundary = "boundaryboundary";
const mailData = [
`MIME-Version: 1.0`,
`To: ${toEmail}`,
`From: "${name}" <${fromEmail}>`,
`Subject: =?UTF-8?B?${Utilities.base64Encode(subject, Utilities.Charset.UTF_8)}?=`,
`Content-Type: multipart/alternative; boundary=${boundary}`,
``,
`--${boundary}`,
`Content-Type: text/plain; charset=UTF-8`,
``,
textBody,
``,
`--${boundary}`,
`Content-Type: text/html; charset=UTF-8`,
`Content-Transfer-Encoding: base64`,
``,
Utilities.base64Encode(htmlBody, Utilities.Charset.UTF_8),
``,
`--${boundary}--`,
].join("\r\n");
return Utilities.base64EncodeWebSafe(mailData);
}
// Please run this function.
function main() {
const toEmail = "###"; // Please set the email for `to`.
const fromEmail = "###"; // Please set the email for `from`.
const name = "ABC";
const subject = "Hello World ・";
const textBody = "sample text body ・";
const htmlBody = "<p>Hello World ・</p>";
var raw = convert(toEmail, fromEmail, name, subject, textBody, htmlBody);
Gmail.Users.Messages.send({raw: raw}, "me");
}
const emailAddress = = "###"; // Please set the email for `to`.
const subject = 'Hello World ・';
GmailApp.sendEmail(
emailAddress,
`=?UTF-8?B?${Utilities.base64Encode(Utilities.newBlob(subject).getBytes())}?=`,
"sample text body"
);