触发日期倒计时时发送电子邮件

时间:2018-11-25 21:17:50

标签: google-apps-script

我正在尝试设置一个包含不同电子邮件地址的工作表, 日期。当日期(到期)倒数20次时,我想发送 问题的所有者自动发送电子邮件。同一行中的所有信息 只是变化列。我在这里发布了半功能脚本,我可以根据日期获取要提取的正确订单项,而我无法获取脚本来提取与日期关联的电子邮件。或者,我收到大量我不想要的电子邮件。 Sheet 任何帮助将不胜感激!

function checkReminder() {
// get the spreadsheet object
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();

// set the first sheet as active
SpreadsheetApp.setActiveSheet(spreadsheet.getSheets()[0]);

// fetch this sheet
var sheet = spreadsheet.getActiveSheet();

// Number of rows to process
 var numRows = sheet.getLastRow()-1;   

// figure out what the last row is
var lastRow = sheet.getLastRow();

// the rows are indexed starting at 1, and the first row
// is the headers, so start with row 2
var startRow = 2;

// Fetch the range of cells A2:B3 
var dataRange = sheet.getRange(startRow, 2 ,lastRow, 
sheet.getLastColumn());

// Fetch values for each row in the Range.
var data = dataRange.getValues();
//Logger.log(data)

 // grab column 20 (the 'days left' column) changed  numrow to last r 
row 
get last row change
var range = sheet.getRange(startRow,20,lastRow-startRow+1,1 );
var numRows = range.getNumRows();
var days_left_values = range.getValues();

// Now, grab the reminder name column
range = sheet.getRange(2, 16, lastRow-startRow+1, 1);
var reminder_name_values = range.getValues();

var warning_count = 0;
var msg = "";
//msg = msg + "Trial Reminder Trial: "+reminder_name+" is due in 
"+days_left+" days.\n"

//for (i in data) {
// var row = data[i];

// First column
//  var emailAddress = row[13];  

// Recipe column (Priority HIGH)
 // var message = row[14]; 
 // var subject = "Reminder CAPA ";
//subject = subject + reminder_name;

// Loop over the days left values
for (var k = 0; k <= numRows-1; k++) {
var days_left = days_left_values[k][0];
if(days_left == 20) {

  // if it's exactly 20, do something with the data.
  var reminder_name = reminder_name_values[k][0];

  msg = msg + "Reminder CAPA: "+reminder_name+" is due in 
"+days_left+" days.\n";
  warning_count++;
}
if(warning_count) {
//MailApp.sendEmail(emailAddress, subject, message); 
Logger.log(msg);

}  

}}

0 个答案:

没有答案