Here is an Apps Script that does this. You can click this start scripting link to open script editor in Google Drive. Then:
- Replace the placeholder in the editor with the script given below.
- Go to "Resources > This project's triggers", and set a trigger to run autoreply every 5 minutes.
The logic of the script is explained below.
function autoReply() {
var interval = 5; // if the script runs every 5 minutes; change otherwise
var date = new Date();
var day = date.getDay();
var hour = date.getHours();
if ([5,6,0].indexOf(day) > -1 || (day == 1 && hour < 8) || (day == 4 && 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("I am out of office. Your email will not seen until Monday morning.");
}
}
}
The script only does something if the current local day/time is
- Friday, Saturday, Sunday (days 5,6,0 in the part
[5,6,0].indexOf(day)
), or
- Monday before 8 am (day 1, hour < 8)
- Thursday after 5 pm (day 4, hour >= 17)
What it does is check all messages received in the last 5 minutes (interval
in the script) and replies to each with a canned text.
It is important that the two time intervals match: the interval at which the trigger is set, and the one set in the script. Otherwise the script will either fail to reply to some messages, or will reply several times.
Remarks
You can try to run this every minute instead of every 5 minutes; but I wasn't sure if this would exceed the maximal running time allowed to scripts for a day (1 hour total running time).
I considered more sophisticated forms of this: with adding a label "auto-reply", or with storing the time of last run in ScriptProperties. But the above gets the job done, and wins in simplicity.