Last active
January 24, 2017 06:53
-
-
Save halida/98a4de03de83d9b7aeba365a24da4503 to your computer and use it in GitHub Desktop.
gmail auto reply schedule
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 scheduled_date = [ | |
'2016-12-19', '2016-12-20', | |
]; | |
var auto_reply = "I am out of office. Your email will not seen until Monday morning."; | |
var now = new Date(); | |
var today = now.toISOString().slice(0, 10); // today format: '2017-01-01' | |
var label = GmailApp.getUserLabelByName('auto-replyed') || GmailApp.createLabel('auto-replyed'); | |
// today is the scheduled date | |
if (scheduled_date.indexOf(today) >= 0) { | |
// get all email inbox, unread, without label auto-replyed | |
var threads = GmailApp.search('is:unread is:inbox -{label:auto-replyed}'); | |
for (var i = 0; i < threads.length; i++) { | |
var thread = threads[i] | |
// reply the email and add auto-replyed label | |
thread.reply(auto_reply); | |
thread.addLabel(label); | |
} | |
} | |
} |
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 auto_reply = "Thank you for your email. Your message is important to us and we will respond as soon as possible. \n\ | |
Client Service Desk \n\ | |
Monday - Friday: 8:00 am - 5:00 pm CT"; | |
var now = new Date(); | |
var label_checked = GmailApp.getUserLabelByName('auto-reply-checked') || GmailApp.createLabel('auto-reply-checked'); | |
var label_replied = GmailApp.getUserLabelByName('auto-replied') || GmailApp.createLabel('auto-replied'); | |
// get all email inbox, unread, without label auto-reply-checked | |
var threads = GmailApp.search('is:unread is:inbox -{label:auto-reply-checked}'); | |
for (var i = 0; i < threads.length; i++) { | |
var thread = threads[i] | |
var thread_date = thread.getLastMessageDate(); | |
var weekday = thread_date.getDay(); | |
var hour = thread_date.getHours(); | |
var is_weekend = (weekday == 0 || weekday > 5); | |
var is_after_work = (hour >= 12 || hour < 8); | |
if ( is_weekend || is_after_work ) { | |
thread.reply(auto_reply); | |
thread.addLabel(label_replied); | |
} | |
thread.addLabel(label_checked); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment