我有一个发送自动电子邮件的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
});
}
编辑2:我注意到发送一个明星(&#34;⭐&#34;)有效,但正常的笑脸(&#34;&#34;)显示为黑色和白色,Unicode风格的图标以及我尝试的其他所有内容都是问号。你能只使用emojis到某个Unicode版本吗?
答案 0 :(得分:4)
我尝试复制表情符号(https://www.emojicopy.com/)并将其直接粘贴到脚本编辑器中:
发送电子邮件后,我收到了我的邮箱:
编辑:
小心一些表情符号是一个字符长度(就像明星一样)但是其他的是两个字符(比如笑容)对于那些有2个字符的人你可以想到在笑脸后立刻写字但是你写的是微笑所以你打破它因此转向问号。
如果您尝试运行此代码,您会看到第一个长度为2,第二个长度为1:
如果你尝试在这两个表情符号上移动指针(在应用程序脚本编辑器中),从表情符号之前到表情符号之后,你会看到在星星的情况下只有一步但是对于微笑你需要2个步骤
答案 1 :(得分:2)
您想发送包含表情符号的HTML正文的电子邮件。如果我的理解是正确的,那么这个修改怎么样?
不幸的是,GmailApp
无法使用最近的表情符号字符。在GmailApp
MailApp
可以使用所有版本的表情符号。
&#34;⭐&#34;是Unicode 5.1。但是&#34;&#34;是Unicode 6.0。这样,在使用GmailApp的脚本中,您可以看到前者,但您无法看到后者。在Michele Pisani的示例脚本中,后者使用MailApp发送。所以角色没有被打破。 &#34;&#34;是Unicode 8.0。
因此,对于您的脚本,修改点如下所示。
MailApp
代替GmailApp
。OR
MailApp
可能对您的情况不起作用。所以我也想提出使用Gmail API的方法。请修改如下。
来自:GmailApp.sendEmail(email, emailSubject, body, {
至 :
MailApp.sendEmail(email, emailSubject, body, {
要使用此功能,请按照以下步骤在Advanced Google Services和API控制台中启用Gmail API。
如果您现在使用使用Gmail API的脚本打开脚本编辑器,则可以通过访问此网址https://console.cloud.google.com/apis/api/gmail.googleapis.com/overview
为项目启用Gmail APIfunction 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()
。如果我误解了你的问题,我很抱歉。
答案 2 :(得分:0)
与SMS收件人一起使用的最简单的完整答案是:
function testNewMail() {
MailApp.sendEmail({
to: "yourphonenumbergoeshere@mymetropcs.com",
subject: "Logos",
htmlBody: "? hi todd happy day"
});
}