如何自定义我创建的 Google Apps 脚本?

How can I customise the Google Apps Script I created?

所以之前我做了一个脚本如下:

  function autoReply() {
  var interval = 5;    //  if the script runs every 5 minutes; change otherwise
  var date = new Date();
  var day = date.getDay();
  var hour = date.getHours();
  if ([4,5,6,0].indexOf(day) > -1 || (day == 1 && hour < 9) || (day == 3 && hour >= 17)) {
    var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
    var threads = GmailApp.search('is:inbox after:' + timeFrom);
    for (var i = 0; i < threads.length; i++) {
      if (threads[i].isUnread()){
      threads[i].reply("xxxx");
      threads[i].markRead();
      threads[i].markImportant();
      }
    }
  }
}

部分

xxxx

是我希望我的读者检查的词。但是,它们以纯文本形式出现,我想知道如何修改脚本以包含我的默认 Gmail 签名和 HTML 元素?

在此先感谢您。

编辑:我已经设置了转发和回复使用的签名。但是我怎样才能通过给定的脚本直接使用它们呢?

我收到的自动重播如下所示:

所以这里有什么问题??

解决方案

关于 HTML 正文

现在您正在使用 .reply(String body) 方法签名。此方法只接受一个字符串参数,表示将作为回复发送的电子邮件正文。

为了使用更多参数,例如 HTML 正文,您必须使用 reply(String body, Object options) 签名。此方法接受一个额外的 JavaScript 对象参数,该参数可以包含这些字段:

  • cc String: a comma separated list of email addresses to CC
  • bcc String: a comma separated list of email addresses to BCC
  • htmlBody String: if set, devices capable of rendering HTML will use it >instead of the required body argument; you can add an optional inlineImages field in HTML body if you have inlined images for your email
  • name String: the name of the sender of the email (default: the user's name)
  • from String: the address that the email should be sent from, which must be one of the values returned by GmailApp.getAliases()
  • replyTo String: an email address to use as the default reply-to address (default: the user's email address)
  • noReply Boolean: true if the email should be sent from a generic no-reply email address to discourage recipients from responding to emails; this option is only possible for G Suite accounts, not Gmail users
  • attachments BlobSource[]: an array of files to send with the email
  • inlineImages Object: a JavaScript object containing a mapping from image key (String) to image data (BlobSource); this assumes that the htmlBody parameter is used and contains references to these images in the format

关于签名

确保您已在 Gmail 设置中为 ON REPLY/FORWARD USE 设置默认签名。

参考资料

GmailThread reply(String,Object)

Gmail Settings