Created
August 1, 2022 07:10
-
-
Save empeje/143bb8dbaf204e1f637aab5735372a78 to your computer and use it in GitHub Desktop.
Autoreply Gmail out of office hours
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment