【问题标题】:apps script reocurring out of office message应用程序脚本重复出现不在办公室消息
【发布时间】:2017-04-03 13:24:45
【问题描述】:

尝试获取应用脚本来检查消息进入的星期几,并在某些日子(例如周六和周日)收到消息时自动回复消息。我希望对消息中的文本进行一些格式化,以包括某些文本的颜色、回车符等。我有以下代码处理两个错误。 1.回复文字没有格式化。 2. 如果其他人打开了外出消息,我最终会收到一个循环的电子邮件。是否可以通过向自动回复回复的消息线程添加标签来解决此问题?

提前感谢您的帮助。

function autoReply() {
  var interval = 5;          //  if the script runs every 5 minutes; change otherwise
  var daysOff = [6,0];   // 1=Mo, 2=Tu, 3=We, 4=Th, 5=Fr, 6=Sa, 0=Su
  var message = "**Auto Reply**  Thank you for your email!   I am out of the office for the weekend spending time with my family. I will be back in the office Monday at 8:00 am.  My usual office hours are Monday- Friday 8:00 am-4:00 pm EST. I monitor email periodically over weekends for emergencies.  I look forward to assisting you.  Thank you!";
  var date = new Date();
  var day = date.getDay();
  if (daysOff.indexOf(day) > -1) {
    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++) {
      threads[i].reply(message);
    }
  }
}

【问题讨论】:

    标签: google-apps-script


    【解决方案1】:

    首先,您的消息没有任何格式。本质上,您发送的是纯文本响应。在字符串中使用 HTML 格式并将其用作 htmlBody 参数(阅读更多关于它们的信息here)。

    接下来是回复循环。谷歌有一个内置的办公室外回复系统,他们这样做的方式是每隔几天才会有人收到自动回复。我建议做类似的事情。一旦您的脚本触发,您就可以使用PropertiesService.getUserProperties() 存储电子邮件(阅读更多关于它们的信息here)。所以基本上你会做

    PropertiesService.getUserProperties().setProperty(email, date)
    

    您应该从收到的电子邮件中获取email,并且您已经拥有date。请记住,您可能希望获取所有涉及的电子邮件并使用相同的消息通知每个人,因此您必须循环访问它们以为每封电子邮件创建单独的条目。

    因此,您希望在函数开始时尽早收到电子邮件,然后尝试 PropertiesService.getUserProperties().getProperty(email),如果您设法检索到非 nullundefined 属性,您应该退出函数并使用return 因为你已经给他们发了回复,现在不需要了。

    【讨论】:

      猜你喜欢
      • 2016-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-13
      • 1970-01-01
      • 1970-01-01
      • 2014-10-23
      • 1970-01-01
      相关资源
      最近更新 更多