有没有办法将表情符号插入Google Apps脚本?

时间:2018-06-04 17:56:06

标签: email google-apps-script gmail emoji

我有一个发送自动电子邮件的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 + "'>&ldquo;" + title + "&rdquo;</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>&nbsp;&nbsp;|&nbsp;&nbsp;<a href='mailto:leshutt@vt.edu' style='text-decoration:none'>Feedback</a>&nbsp;&nbsp;|&nbsp;&nbsp;<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版本吗?

3 个答案:

答案 0 :(得分:4)

我尝试复制表情符号(https://www.emojicopy.com/)并将其直接粘贴到脚本编辑器中:

enter image description here

发送电子邮件后,我收到了我的邮箱:

enter image description here

编辑:

小心一些表情符号是一个字符长度(就像明星一样)但是其他的是两个字符(比如笑容)对于那些有2个字符的人你可以想到在笑脸后立刻写字但是你写的是微笑所以你打破它因此转向问号。

如果您尝试运行此代码,您会看到第一个长度为2,第二个长度为1:

enter image description here

如果你尝试在这两个表情符号上移动指针(在应用程序脚本编辑器中),从表情符号之前到表情符号之后,你会看到在星星的情况下只有一步但是对于微笑你需要2个步骤

答案 1 :(得分:2)

您想发送包含表情符号的HTML正文的电子邮件。如果我的理解是正确的,那么这个修改怎么样?

关于GmailApp和MailApp:

  • 不幸的是,GmailApp无法使用最近的表情符号字符。在GmailApp

    • 表情符号小于Unicode 5.2可以用于这种情况。
    • emoji超过Unicode 6.0不能用于这种情况。
  • MailApp可以使用所有版本的表情符号。

&#34;⭐&#34;是Unicode 5.1。但是&#34;&#34;是Unicode 6.0。这样,在使用GmailApp的脚本中,您可以看到前者,但您无法看到后者。在Michele Pisani的示例脚本中,后者使用MailApp发送。所以角色没有被打破。 &#34;&#34;是Unicode 8.0。

修改要点:

因此,对于您的脚本,修改点如下所示。

  • 使用MailApp代替GmailApp

OR

  • 使用Gmail API。
    • 从您对Michele Pisani的评论中,我担心MailApp可能对您的情况不起作用。所以我也想提出使用Gmail API的方法。

1。修改了你的脚本

请修改如下。

来自:
GmailApp.sendEmail(email, emailSubject, body, {
至 :
MailApp.sendEmail(email, emailSubject, body, {

2。使用Gmail API

要使用此功能,请按照以下步骤在Advanced Google Services和API控制台中启用Gmail API。

在高级Google服务中启用Gmail API v1

  • 在脚本编辑器上
    • 资源 - &gt;高级Google服务
    • 启用Gmail API v1

Enable Gmail API at API console

  • 在脚本编辑器上
    • 资源 - &gt;云平台项目
    • 查看API控制台
    • 在“入门”中,单击“启用API”并获取密钥等凭据。
    • 在左侧,单击“库”。
    • 在搜索API&amp;服务,输入&#34; Gmail&#34;。然后点击Gmail API。
    • 单击“启用”按钮。
    • 如果API已启用,请不要关闭。

如果您现在使用使用Gmail API的脚本打开脚本编辑器,则可以通过访问此网址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 + "'>&ldquo;" + title + "&rdquo;</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>&nbsp;&nbsp;|&nbsp;&nbsp;<a href='mailto:leshutt@vt.edu' style='text-decoration:none'>Feedback</a>&nbsp;&nbsp;|&nbsp;&nbsp;<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");
  }
}
注意 :
  • 使用此示例时,请声明emailfirstName
  • 请运行myFunction()

参考文献:

如果我误解了你的问题,我很抱歉。

答案 2 :(得分:0)

与SMS收件人一起使用的最简单的完整答案是:

function testNewMail() {
 MailApp.sendEmail({
    to: "yourphonenumbergoeshere@mymetropcs.com",
    subject: "Logos",
    htmlBody: "? hi todd happy day"
  }); 
}