Jump to content

Recommended Posts

Posted

I have been asked if there is a way to put an automatic Out of Office on for some users GMail for after 5pm and at weekends. So anyone emailing after 5pm gets an email back to say "its now out of hours and email will be dealt with tomorrow" or after 5pm friday "its now the weekend and emails will be dealt with on monday". I have responded to say its a work culture thing and should be a policy. Shouldn't rely on technology to solve it but it got me googling.

 

I have come across a Google Apps Script that purports to do exactly this. When I did some tests it sort of worked but sent me out of office reply emails as well as the person sending the emails, then just got into a loop.

 

If anyone has any experience and can decipher where this script is going wrong I would appreciate some help.

 

The script is taken from here : google apps script - Any way to send Gmail Out of Office/Auto-reply at the same times every week? - Web Applications Stack Exchange

 

function autoReply() {
 var interval = 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 contacting us. The office is now closed. All emails will be attended to when the office re-opens at 9:00am on Monday morning.";
 var wkdayMessage = "Hi, Thank you for contacting us. The office is now closed. All emails will be attended to when the office re-opens in the morning.";
 var date = new Date();
 var day = date.getDay();
 var hour = date.getHours();
 if (wkend.indexOf(day) > -1 || (day == 5 && 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++) {
     threads[i].reply(wkendMessage);
   }
 }
 else if (hour < 9 || 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++) {
     threads[i].reply(wkdayMessage);
   }
 }
}

Posted
I'm not sure about the script (I'd suggest posting in the UK GEG community on G+ - someone like Oli Trussell will know). For the weekend ones, you can do this with a content compliance rule. Put the users into a Sub-OU and apply a mail rule that which matches Sat or Sun in the header - set it to send an automated reply. Not tried it - but should work - but not with a time.
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...