function reminder() {
var sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
var data = sh.getDataRange().getValues()
var d = new Date().getTime();
for (var i=1;i<data.length;i ){
if (data[i][4]<=new Date(d 7*24*60*60*1000) && data[i][4]>=new Date(d 5*24*60*60*1000) && data[i][6]==''){
MailApp.sendEmail({to:data[i][3],
subject: 'Reminder Process Update Required in 1 week',
htmlBody: 'Hello ' data[i][2] ', the process page for <b>' data[i][1] '</b> is due for review in 1 week. Please review the content and contact the Process team before its due date if amendments are required.'
})
sh.getRange(i 1,7).setValue('sent')
}
else if (data[i][4]<=new Date(d 30*24*60*60*1000) && data[i][4]>=new Date(d 28*24*60*60*1000) && data[i][5]==''){
MailApp.sendEmail({to:data[i][3],
subject: 'Reminder Process Update Required in 1 month',
htmlBody: 'Hello ' data[i][2] ', the process page for <b>' data[i][1] '</b> is due for review in review in 1 month. Please review the content and contact the Process Mapping team before its due date if amendments are required.'
})
sh.getRange(i 1,6).setValue('sent')
}
}
}
因此,目前它正在向“data [i] [3]”發送電子郵件,我還想添加最多 2 個其他收件人,它將與那里的內容一起發送電子郵件,但如果這些欄位留空,它應該只發出電子郵件到填寫的欄位。
下面是作業表和腳本演示的鏈接 - https://docs.google.com/spreadsheets/d/1Qw8WefbVkS-AQXi1CcZ0z2CL-P0oNSZYqeT40oVF6go/edit?usp=sharing
uj5u.com熱心網友回復:
我相信你的目標如下。
- 您想使用“D”到“F”列值的收件人電子郵件地址。
- 在您的顯示腳本中,您使用的是“A”到“G”列。在這種情況下,電子郵件地址是“D”列。但在您的問題中,電子郵件地址是“D”到“F”列。并且,您想使用“A”到“I”列。即,您在顯示腳本中添加了 2 列。
在這種情況下,如何進行以下修改?
修改后的腳本:
在此修改中,“D”到“F”列的值用作收件人電子郵件地址。當“D”到“F”列的值沒有值時,MailApp.sendEmail不運行。而且,對于電子表格的新結構,修改了 for 回圈中每一行的索引。
function reminder() {
var sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var data = sh.getDataRange().getValues();
var d = new Date().getTime();
for (var i = 1; i < data.length; i ) {
var recipients = data[i].slice(3, 6).filter(String).join(",");
if (recipients == "") continue;
if (data[i][6] <= new Date(d 7 * 24 * 60 * 60 * 1000) && data[i][6] >= new Date(d 5 * 24 * 60 * 60 * 1000) && data[i][7] == '') {
MailApp.sendEmail({
to: recipients,
subject: 'Reminder Process Update Required in 1 week',
htmlBody: 'Hello ' data[i][2] ', the process page for <b>' data[i][1] '</b> is due for review in 1 week. Please review the content and contact the Process team before its due date if amendments are required.'
});
sh.getRange(i 1, 9).setValue('sent');
}
else if (data[i][6] <= new Date(d 30 * 24 * 60 * 60 * 1000) && data[i][6] >= new Date(d 28 * 24 * 60 * 60 * 1000) && data[i][7] == '') {
MailApp.sendEmail({
to: recipients,
subject: 'Reminder Process Update Required in 1 month',
htmlBody: 'Hello ' data[i][2] ', the process page for <b>' data[i][1] '</b> is due for review in review in 1 month. Please review the content and contact the Process Mapping team before its due date if amendments are required.'
});
sh.getRange(i 1, 8).setValue('sent');
}
}
}
筆記:
- 此修改后的腳本假定您的顯示腳本適用于“A”到“G”列的電子表格。請注意這一點。
- 此修改后的腳本適用于您的示例電子表格。當您更改電子表格的結構時,此腳本可能無法使用。所以請注意這一點。
參考:
- 發送電子郵件(訊息)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/416497.html
標籤:
