Answers:
我根据您的情况对类似问题做了回答。如果当前日期是星期四(4),星期五(5),星期六(6)或星期日(0)之一,则此Apps脚本将进行答复。可以按照以下指示调整天数。
function autoReply() {
var interval = 5; // if the script runs every 5 minutes; change otherwise
var daysOff = [4,5,6,0]; // 1=Mo, 2=Tu, 3=We, 4=Th, 5=Fr, 6=Sa, 0=Su
var message = "This is my day off.";
var date = new Date();
var day = date.getDay();
if (daysOff.indexOf(day) > -1) {
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(message);
}
}
}
我已经写了一个与user79865相比的更新版本,为回复的电子邮件添加标签而不是使用时间,这样会更准确。
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);
}
}
}
我将这两个脚本结合在一起,得到了带有linjunhalida标签的版本,但是能够选择日期而不是输入日期,例如在user79865的脚本中:
function autoReply() {
var scheduled_date = [
'2019-09-20', '2019-09-27',
];
var auto_reply = "I am out of office today. I'll get back to you as soon as possible next week.";
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);
}
}
}
使用一段时间后,您可能还需要查看其他一些陷阱和改进:
function autoReply() {
var interval = 5; // if the script runs every 5 minutes; change otherwise
var daysOff = [1,5,6,0]; // 1=Mo, 2=Tu, 3=We, 4=Th, 5=Fr, 6=Sa, 0=Su
var date = new Date();
var day = date.getDay();
var label = GmailApp.getUserLabelByName("autoresponded");
if (daysOff.indexOf(day) > -1) {
var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
var threads = GmailApp.search('is:inbox !label:autoresponded after:' + timeFrom);
for (var i = 0; i < threads.length; i++) {
var message = threads[i].getMessages()[0];
if (message.getFrom().indexOf("myemail@gmail.com") < 0 && message.getFrom().indexOf("no-repl") < 0 && message.getFrom().indexOf("bounce") < 0 && message.getFrom().indexOf("spam") < 0) {
threads[i].reply("", {
htmlBody: "<p>Thank you for your message. I am not in the office today. If you have urgent questions you can email office@example.com. If you have other urgent enquiries you can call the office on 1800 999 002.</p><p>Best regards,<br>Name</p>"
});
label.addToThread(threads[i]);
}
}
}
}