我有一个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
});
}
我注意到发送星号(“⭐”)是可行的,但是正常的笑脸(“😊”)显示为黑白的Unicode风格的图标,而我尝试过的其他一切都是问号。您只能使用特定Unicode版本以下的表情符号吗?
最佳答案
您要发送包含表情符号的HTML正文电子邮件。如果我的理解是正确的,那么该修改如何?
关于GmailApp和MailApp:
GmailApp
无法使用最近的表情符号字符。在GmailApp
小于Unicode 5.2的
MailApp
可以使用所有版本的表情符号。 “⭐”是Unicode 5.1。但是“😊”是Unicode 6.0。这样,在使用GmailApp的脚本中,您可以看到前者,但是看不到后者。在Michele Pisani的示例脚本中,后者是使用MailApp发送的。所以角色没有坏掉。 “🤖”是Unicode 8.0。
修改要点:
因此,对于您的脚本,修改点如下。
MailApp
代替GmailApp
。 或者
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
Enable Gmail API at API console
如果现在要使用用于使用Gmail API的脚本打开脚本编辑器,则可以通过访问以下URL来为该项目启用Gmail API https://console.cloud.google.com/apis/api/gmail.googleapis.com/overview
示例脚本:
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()
。 引用 :
如果我误解了您的问题,对不起。
关于email - 如何在通过GmailApp发送的电子邮件中插入表情符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50686254/