【问题标题】:How to insert an emoji into an email sent with GmailApp?如何在使用 GmailApp 发送的电子邮件中插入表情符号?
【发布时间】:2018-11-14 02:58:23
【问题描述】:

我有一个发送自动电子邮件的 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
  });
}

我注意到发送星号(“⭐”)有效,但正常的笑脸(“????”)显示为黑白、Unicode 风格的图标以及我所拥有的所有其他内容试过的是问号。只能使用特定 Unicode 版本的表情符号吗?

【问题讨论】:

  • 你能提供你使用的脚本吗?我认为它会帮助用户思考解决方案。
  • 您的问题已经解决了吗?如果您仍在寻找解决方案,能否请您告诉我您目前的问题情况?如果您的问题已经解决,对不起。
  • 嗨@Tanaike,不幸的是,我无法解决它。每当我将表情符号复制并粘贴到脚本中时,即使我在前后添加了一堆空格,它仍然会在电子邮件中显示为问号。 :\
  • 感谢您的回复。我发布了我的答案。你能确认一下吗?

标签: email google-apps-script gmail emoji


【解决方案1】:

您想发送一封带有 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。
    • 从您的 cmets 到 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 控制台
    • 在开始时,单击启用 API 并获取密钥等凭据。
    • 点击左侧的库。
    • 在搜索 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 + "'>&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】:

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

    发送电子邮件后,我在邮箱中收到了它:

    编辑:

    请注意,有些表情符号是一个字符长度(如星星),而另一些是 2 个字符(如微笑),对于那些有 2 个字符的表情,您可以考虑在微笑后立即书写,但您是在微笑内书写,所以你打破它因此变成问号。

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

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

    【讨论】:

    • 嗨,我尝试从 emojicopy 复制和粘贴相同的表情符号,但得到了一堆这样的问号:������ 我在上面添加了我的代码,你能看看如果我做错了什么?
    • 我通过添加更多细节修改了我的答案
    • 谢谢,我想我需要澄清一下。我正在尝试使用机器人表情符号(?)。我确实运行了您提供的记录器代码,它返回机器人面部的“2.0”,所以我知道它是两个字符。我试过将它粘贴到多个空格上,粘贴到两边都有额外空间的空间中,但它仍然带有问号。也许我只是迟钝-您介意告诉我确切的粘贴方法,这样我就不会覆盖字符吗? :)
    【解决方案3】:

    也适用于 SMS 收件人的最简单的完整答案是:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-20
      • 2011-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      相关资源
      最近更新 更多