发送电子邮件到Google电子表格

时间:2018-06-22 10:12:00

标签: google-apps-script google-sheets

发送电子邮件到Google电子表格。 我为Google表格发出警报,在发送按钮的开头,将许多相同的消息发送到E-mail,这不是我的代码中重复该消息的情况。只要发送的100条消息不会过期就被循环。也许有人知道原因? 先感谢您! 我的代码:

function onOpen(e) {
var spreadsheet = SpreadsheetApp.getActive();
var menuItems = [
  {name: 'Відправити E-mail', functionName: 'sendArticleCountEmails'}
];
spreadsheet.addMenu('Відправити E-mail', menuItems);
}




function sendArticleCountEmails() {

var sheet = SpreadsheetApp.getActiveSheet();

var column1 =  sheet.getRange('B27').getValue();

var column2 = sheet.getRange('B28').getValue();
var column3 = sheet.getRange('B29').getValue(); 
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.setActiveSheet(ss.getSheetByName("Постачальники"));
var dataRange = ss.getRange("AJ2:AV200");
var data = dataRange.getValues();
var column4 = sheet.getRange("H4:U999").getValues();
var column5 = sheet.getRange("K4:K999").getValues();
 for(i in column4){
 if(i==0){
 var rowJ = 4;
 }
 var rowI = column4[i];

 var status1 = rowI[5];
 var status2 = rowI[9];
 var status3 = rowI[13];
 var code = rowI[0];
 if(rowI==0 ){
 rowJ++;
 }
 else {
var day = sheet.getRange("AH999").setFormula("=(TRUNC(VALUE(NOW()))- 
TRUNC(VALUE(I"+rowJ+")))");
 var days = sheet.getRange("AH999").getValue();
if(days >= column1 && days<column2 && status1 == 0 && status2 == 0 && 
status3 == 0){
  sendMessage(code, data, sheet);
 } else if (days >= column2 && days<column3 &&  status2 == 0 && status3 == 
0){
   sendMessage(code, data, sheet);
}else if (days >= column3 && status3 == 0){
   sendMessage(code, data, sheet);

 }
 rowJ++;
}
}
  }
 function sendMessage(code, data,sheet){
  for (i in data) {
  var rowData = data[i];
  var privider = rowData[0]
   var email = rowData[9];
  var copyEmail = rowData[12];
   var emailAddress = email;      
  var message1 = rowData[10];
  var message = message1+code;
  var sub = rowData[11];
  var subject = sub;
  if(privider == sheet.getName()){
  MailApp.sendEmail(emailAddress, subject, message);
  break;
       }
   }

 }

0 个答案:

没有答案