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("");
}