Rav*_*lon 2 javascript gmail google-sheets google-apps-script emoji
我正在尝试使用 Google Apps 脚本发送电子邮件。
\n// try 1\nconst subject = \'Hello World \';\n\n// try 2\nconst subject = \'Hello World \' + String.fromCodePoint(\'0x1F600\');\n\nGmailApp.sendEmail(\n \'abc@gmail.com\', subject, \'\',\n {htmlBody: \'<p>Hello World </p>\', name: \'ABC\'}\n);\nRun Code Online (Sandbox Code Playgroud)\n当我使用 \xe2\xad\x90 时,它在主题和 HTML 正文中都能完美运行。但是,当我使用 时,它在主题和 HTML 正文中显示带有问号的黑色菱形。
\n我还检查了如何将表情符号插入使用 GmailApp 发送的电子邮件中?但它只展示了如何在电子邮件正文中使用它,而不是主题。
\n我尝试过使用 MailApp 并且它有效,但由于某些原因我不想使用它。
\n关于如何解决这个问题有什么想法吗?
\n我相信你的目标如下。
\n\xee\x81\x9e\xe3\x83\xbb您想要使用 Google Apps 脚本发送包含主题中的表情符号的 Gmail 。GmailApp.sendEmail您想知道使用而不使用来实现目标的方法MailApp.sendEmail。GmailApp.sendEmail使用时,主题可以包含表情符号。但表情符号不能在电子邮件正文中使用。所以我建议在这种情况下使用Gmail API。对于我的问题as other direction, in your goal, can you use Gmail API?,你回答了Yes, Gmail API will work.。所以我了解到您的目标可以使用 Gmail API 来实现。\xee\x81\x9e\xe3\x83\xbb,主题会作为 Base64 数据发送。\nGmailApp.sendEmail.当以上几点反映到脚本中时,就会变成如下所示。
\n在使用此脚本之前,请在高级 Google 服务中启用 Gmail API。并且,请在函数中设置变量main()并运行该函数main()。
function convert(toEmail, fromEmail, name, subject, textBody, htmlBody) {\n const boundary = "boundaryboundary";\n const mailData = [\n `MIME-Version: 1.0`,\n `To: ${toEmail}`,\n `From: "${name}" <${fromEmail}>`,\n `Subject: =?UTF-8?B?${Utilities.base64Encode(subject, Utilities.Charset.UTF_8)}?=`,\n `Content-Type: multipart/alternative; boundary=${boundary}`,\n ``,\n `--${boundary}`,\n `Content-Type: text/plain; charset=UTF-8`,\n ``,\n textBody,\n ``,\n `--${boundary}`,\n `Content-Type: text/html; charset=UTF-8`,\n `Content-Transfer-Encoding: base64`,\n ``,\n Utilities.base64Encode(htmlBody, Utilities.Charset.UTF_8),\n ``,\n `--${boundary}--`,\n ].join("\\r\\n");\n return Utilities.base64EncodeWebSafe(mailData);\n}\n\n// Please run this function.\nfunction main() {\n const toEmail = "###"; // Please set the email for `to`.\n const fromEmail = "###"; // Please set the email for `from`.\n const name = "ABC";\n const subject = "Hello World \xee\x81\x9e\xe3\x83\xbb";\n const textBody = "sample text body \xee\x81\x9e\xe3\x83\xbb";\n const htmlBody = "<p>Hello World \xee\x81\x9e\xe3\x83\xbb</p>";\n var raw = convert(toEmail, fromEmail, name, subject, textBody, htmlBody);\n Gmail.Users.Messages.send({raw: raw}, "me");\n}\nRun Code Online (Sandbox Code Playgroud)\n当您想使用带有主题的表情符号时GmailApp.sendEmail,还可以使用以下脚本。但是,在这种情况下,在我的环境中,当表情符号包含在文本正文和 HTML 正文中时,表情符号就看不到了。所以请小心这一点。
const emailAddress = = "###"; // Please set the email for `to`.\n const subject = \'Hello World \xee\x81\x9e\xe3\x83\xbb\';\n GmailApp.sendEmail(\n emailAddress,\n `=?UTF-8?B?${Utilities.base64Encode(Utilities.newBlob(subject).getBytes())}?=`,\n "sample text body"\n );\nRun Code Online (Sandbox Code Playgroud)\n| 归档时间: |
|
| 查看次数: |
2507 次 |
| 最近记录: |