如何在用GmailApp发送的电子邮件中插入表情符号? [英] How to insert an emoji into an email sent with GmailApp?
本文介绍了如何在用GmailApp发送的电子邮件中插入表情符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个发送自动电子邮件的GAS脚本,并想包括几个表情符号。我尝试了使用快捷码和复制/粘贴,但到目前为止似乎都没有奏效。我只是想看看我有没有遗漏什么。
编辑:代码如下:
var title = rowData.publicationTitle;
var journal = rowData.journalTitle;
var url = rowData.publicationUrl;
//Emoji goes here in the body:
var body = "Hi " + firstName + "!<br><br>I noticed your article <a href='" + url + "'>“" + title + "”</a> was recently published in <i>" + journal + "</i>. Congratulations! This is just a friendly reminder to please upload your original document and a PDF version to our publications app when you have time.<br><br>To upload your publication, you can <a href='http://support.cpes.vt.edu/publishing'>click here</a>.<br><br>Thanks!<br><br>🤖 CB<br><br><hr style='background-color: #d8d8d8; border: 0 none; color: #d8d8d8; height: 1px;'><span style='font-size:12px'><b>CPES Publications Reminders</b> | <a href='mailto:leshutt@vt.edu' style='text-decoration:none'>Feedback</a> | <a href='http://support.cpes.vt.edu/publishing' style='text-decoration:none;'>Publication uploads</a></span>";
var emailSubject = "Just a reminder to upload your article!";
var me = Session.getActiveUser().getEmail();
var aliases = GmailApp.getAliases();
if (emailStatus == "Pending" && emailData !== "No emails found") {
GmailApp.sendEmail(email, emailSubject, body, {
from: aliases[2],
name: "CPES Bot",
htmlBody: body
});
}
我注意到发送星号(&⭐&q;)有效,但普通的笑脸(&😊&q;)显示为黑白的unicode样式的图标,而我尝试的其他所有内容都是问号。您只能使用特定Unicode版本之前的表情符号吗?
推荐答案
您要发送包含表情符号的电子邮件。如果我的理解是正确的,那么这个修改怎么样?
关于GmailApp和MailApp:
遗憾的是,
GmailApp
不能使用最近的表情符号。在GmailApp
- 低于Unicode 5.2的表情符号可用于此情况。
- 超过Unicode 6.0的表情符号无法用于此情况。
MailApp
可以使用所有版本的emoji。
"⭐"是Unicode5.1。但"😊"是Unicode6.0。这样,在使用GmailApp的脚本中,您可以看到前者,但看不到后者。在Michele Pisani的一个示例脚本中,后者是使用MailApp发送的。因此,这个角色并没有被打破。"🤖"为Unicode8.0。
修改点:
因此,对于您的脚本,修改点如下所示。
- 使用
MailApp
而不是GmailApp
。
或
- 使用Gmail API。
- 从您对Michele Pisani的评论中,我担心
MailApp
可能不适合您的情况。所以我也想提出使用Gmail API的方法。
- 从您对Michele Pisani的评论中,我担心
1.修改了您的脚本
请按如下方式修改。
出发地:GmailApp.sendEmail(email, emailSubject, body, {
致:
MailApp.sendEmail(email, emailSubject, body, {
2.使用Gmail API
若要使用此功能,请在高级Google服务和API控制台启用Gmail API,如下所示。
在高级Google服务中启用Gmail API v1
- 在脚本编辑器上
- 资源->高级Google服务
- 打开Gmail API v1
Enable Gmail API at API console
- 在脚本编辑器上
- 资源->云平台项目
- 查看API控制台
- 在入门处,单击启用API并获取密钥等凭据。
- 在左侧,单击库。
- 在搜索API&;服务时,输入"gmail"。并单击Gmail API。
- 单击"启用"按钮。
- 如果接口已经开启,请不要关闭。
如果您现在正在打开带有使用Gmail API的脚本的脚本编辑器,您可以通过访问此URLhttps://console.cloud.google.com/apis/api/gmail.googleapis.com/overview
为项目启用Gmail API示例脚本:
function convert(email, aliase, emailSubject, body) {
body = Utilities.base64Encode(body, Utilities.Charset.UTF_8);
var boundary = "boundaryboundary";
var mailData = [
"MIME-Version: 1.0",
"To: " + email,
"From: CPES Bot <" + aliase + ">",
"Subject: " + emailSubject,
"Content-Type: multipart/alternative; boundary=" + boundary,
"",
"--" + boundary,
"Content-Type: text/plain; charset=UTF-8",
"",
body,
"",
"--" + boundary,
"Content-Type: text/html; charset=UTF-8",
"Content-Transfer-Encoding: base64",
"",
body,
"",
"--" + boundary,
].join("
");
return Utilities.base64EncodeWebSafe(mailData);
}
function myFunction() {
// Please declare email and firstName.
var title = rowData.publicationTitle;
var journal = rowData.journalTitle;
var url = rowData.publicationUrl;
//Emoji goes here in the body:
var body = "Hi " + firstName + "!<br><br>I noticed your article <a href='" + url + "'>“" + title + "”</a> was recently published in <i>" + journal + "</i>. Congratulations! This is just a friendly reminder to please upload your original document and a PDF version to our publications app when you have time.<br><br>To upload your publication, you can <a href='http://support.cpes.vt.edu/publishing'>click here</a>.<br><br>Thanks!<br><br>🤖 CB<br><br><hr style='background-color: #d8d8d8; border: 0 none; color: #d8d8d8; height: 1px;'><span style='font-size:12px'><b>CPES Publications Reminders</b> | <a href='mailto:leshutt@vt.edu' style='text-decoration:none'>Feedback</a> | <a href='http://support.cpes.vt.edu/publishing' style='text-decoration:none;'>Publication uploads</a></span>";
var emailSubject = "Just a reminder to upload your article!";
var me = Session.getActiveUser().getEmail();
var aliases = GmailApp.getAliases();
if (emailStatus == "Pending" && emailData !== "No emails found"){
// Added script
var raw = convert(email, aliases[2], emailSubject, body);
Gmail.Users.Messages.send({raw: raw}, "me");
}
}
注:
- 使用此示例时,请声明
email
和firstName
。 - 请运行
myFunction()
。
引用:
如果我误解了您的问题,很抱歉。
这篇关于如何在用GmailApp发送的电子邮件中插入表情符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文