Google Script to autoreply email during off-hours
Recently I was amazed by my colleague in europe where they basically reply me with autoreply during after hours. I want to replicate their automatin but there's no native way to do it in Gmail, so I leard that I can do Google AppScript here's the results
function autoReply() {
var interval = 5;
var wkend = [6,0];
var wkendMessage = "Hi! Thank you for contacting me. I'm currently out of office. All emails we'll be replied approximately on next Monday.";
var wkdayMessage = "Hi! Thank you for your email. I'm currently offline. I'll be back Mon-Fri 9-6PM UTC+2. You are getting this email because it is outside business hours.";
var date = new Date();
var day = date.getDay();
var hour = date.getHours();
if (wkend.indexOf(day) > -1 || (day == 5 && hour >= 18)) {
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 >= 18) {
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);
}
}
}
You just need to
- Create account here https://script.google.com/
- Create a new project
- Copy and paste the code
- Deploy the automation
- Setup time based trigger
- Voila, you get automation when someone reaches you during off hours.
Thank you!
I appreciate you for sharing it with us :)
Glad that it useful for you.
Thanks for sharing, I will try it.
Thanks, let me know if you have any feedback!
Thank you so much for sharing this with us.
Glad that it useful for you.