最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

gmail apps script works in test deployment when clicking run, but does not work when deployed - Stack Overflow

programmeradmin0浏览0评论

I set up a gmail auto responder to reply to new email that hits inbox after business hours and on weekends. It works as expected when I manually click "run", but won't run the deployment automatically. I am running the test on the same gmail business account and I'm the administrator, so permissions should be good?

Wondering if my triggers are working correctly? It should run every 10 minutes and view new emails in inbox and send reply message.

I added a new deployment (apps script) and see it in active list. it's a webapp. I have "execute as" set to myself (the gmail email it is deployed on). "who has access" is set to 'only myself' which I think should be good?

function autoReply() {
var interval = 10; //5 if the script runs every 5 minutes; change otherwise
var wkend = [6,0]; // 1=Mo, 2=Tu, 3=We, 4=Th, 5=Fr, 6=Sa, 0=Su
var wkendMessage = "Hi, Thank you for your email. We will respond by the end of the next business day (Monday-Friday 8am-4pm).Thank you";
var date = new Date();
var day = date.getDay();
var hour = date.getHours();
var threads = GmailApp.getInboxThreads();
var messages = threads[0].getMessages();
var senderEmail = messages[0].getFrom();
var matchEmail=false;
var ignoreEmails=["intuit","wpengine"];

for(i=0; i<ignoreEmails.length; i++) {
  if(senderEmail.includes(ignoreEmails[i])) {
    matchEmail = true;
  }
}

if (!matchEmail){
 if (wkend.indexOf(day) > -1 || (day == 5 && hour >= 16)) {
    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(wkendMessage,{
      bcc:'[email protected]',
      noReply:true,});
    }//for
  }//if hours/days

}//if matchemail

}//end function

function doGet() {
 return ContentService.createTextOutput("");
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论