如何在使用 GmailApp 发送的电子邮件中插入表情符号?
How to insert an emoji into an email sent with GmailApp?
我有一个发送自动电子邮件的 GAS 脚本,我想包含几个表情符号。我试过使用短代码和 copying/pasting,但到目前为止似乎没有任何效果。只是想看看有没有我遗漏的东西。
编辑:这是代码:
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
});
}
我注意到发送星号 ("⭐") 有效,但正常的笑脸 ("") 显示为黑白、Unicode 风格的图标,而我尝试过的其他所有内容都是问号。只能使用特定 Unicode 版本的表情符号吗?
我尝试复制表情符号 (https://www.emojicopy.com/) 并将其直接粘贴到脚本编辑器中:
发送电子邮件后,我在邮箱中收到了它:
编辑:
请注意,有些表情符号是一个字符长度(如星星),而其他表情符号是 2 个字符(如微笑),对于那些有 2 个字符的表情符号,你可以认为是在微笑之后立即写,但实际上你是在里面写的微笑所以你打破它因此变成问号。
如果您尝试 运行 这段代码,您会看到第一个长度为 2,第二个长度为 1:
如果您尝试将指针(在应用程序脚本编辑器中)移动到这 2 个表情符号上,从表情符号之前到之后,您会看到在星星的情况下只需一步,但对于您需要的微笑2 个步骤。
您想发送一封正文为 HTML 并包含表情符号的电子邮件。如果我的理解是正确的,这个修改怎么样?
关于 GmailApp 和 MailApp :
很遗憾,GmailApp
不能使用最近的表情符号字符。在 GmailApp
- 低于 Unicode 5.2 的表情符号可用于这种情况。
- 超过 Unicode 6.0 的表情符号不能用于这种情况。
MailApp
可以使用所有版本的表情符号。
"⭐" 是 Unicode 5.1。但是“”是 Unicode 6.0。这样,在您使用 GmailApp 的脚本中,您可以看到前者,但看不到后者。在 Michele Pisani 的示例脚本中,后者是使用 MailApp 发送的。所以人品不坏。 "" 是 Unicode 8.0.
修改点:
所以以你的脚本为例,修改点如下
- 使用
MailApp
代替 GmailApp
。
或
- 使用 Gmail API。
- 根据您对 Michele Pisani 的评论,我担心
MailApp
可能不适合您的情况。所以我也想提出使用Gmail的方法API.
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控制台
- 在开始时,单击启用 APIs 并获取密钥等凭据。
- 在左侧,单击“库”。
- 在搜索 API 和服务时,输入 "Gmail"。然后点击 Gmail API.
- 单击“启用”按钮。
- 如果API已经开启,请不要关闭。
如果您现在打开带有使用 Gmail API 脚本的脚本编辑器,您可以通过访问此 URL https://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("\r\n");
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()
.
参考资料:
如果我误解了你的问题,我很抱歉。
也适用于 SMS 收件人的最简单的完整答案是:
function testNewMail() {
MailApp.sendEmail({
to: "yourphonenumbergoeshere@mymetropcs.com",
subject: "Logos",
htmlBody: " hi todd happy day"
});
}
我有一个发送自动电子邮件的 GAS 脚本,我想包含几个表情符号。我试过使用短代码和 copying/pasting,但到目前为止似乎没有任何效果。只是想看看有没有我遗漏的东西。
编辑:这是代码:
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
});
}
我注意到发送星号 ("⭐") 有效,但正常的笑脸 ("") 显示为黑白、Unicode 风格的图标,而我尝试过的其他所有内容都是问号。只能使用特定 Unicode 版本的表情符号吗?
我尝试复制表情符号 (https://www.emojicopy.com/) 并将其直接粘贴到脚本编辑器中:
发送电子邮件后,我在邮箱中收到了它:
编辑:
请注意,有些表情符号是一个字符长度(如星星),而其他表情符号是 2 个字符(如微笑),对于那些有 2 个字符的表情符号,你可以认为是在微笑之后立即写,但实际上你是在里面写的微笑所以你打破它因此变成问号。
如果您尝试 运行 这段代码,您会看到第一个长度为 2,第二个长度为 1:
如果您尝试将指针(在应用程序脚本编辑器中)移动到这 2 个表情符号上,从表情符号之前到之后,您会看到在星星的情况下只需一步,但对于您需要的微笑2 个步骤。
您想发送一封正文为 HTML 并包含表情符号的电子邮件。如果我的理解是正确的,这个修改怎么样?
关于 GmailApp 和 MailApp :
很遗憾,
GmailApp
不能使用最近的表情符号字符。在GmailApp
- 低于 Unicode 5.2 的表情符号可用于这种情况。
- 超过 Unicode 6.0 的表情符号不能用于这种情况。
MailApp
可以使用所有版本的表情符号。
"⭐" 是 Unicode 5.1。但是“”是 Unicode 6.0。这样,在您使用 GmailApp 的脚本中,您可以看到前者,但看不到后者。在 Michele Pisani 的示例脚本中,后者是使用 MailApp 发送的。所以人品不坏。 "" 是 Unicode 8.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控制台
- 在开始时,单击启用 APIs 并获取密钥等凭据。
- 在左侧,单击“库”。
- 在搜索 API 和服务时,输入 "Gmail"。然后点击 Gmail API.
- 单击“启用”按钮。
- 如果API已经开启,请不要关闭。
如果您现在打开带有使用 Gmail API 脚本的脚本编辑器,您可以通过访问此 URL https://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("\r\n");
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()
.
参考资料:
如果我误解了你的问题,我很抱歉。
也适用于 SMS 收件人的最简单的完整答案是:
function testNewMail() {
MailApp.sendEmail({
to: "yourphonenumbergoeshere@mymetropcs.com",
subject: "Logos",
htmlBody: " hi todd happy day"
});
}