Google sheets script to send email

2020-05-06 13:26发布

问题:

link to the sheet

I just need the script (sendEmail02()) to collect data from the table of only the person whose mail is contained in column 2 and send him all the data in one letter, and so each person in turn. It is necessary that during the iteration, the addresses are read from column 2 and data is collected and sent in a separate letter to each recipient. It would be great if each user was sent only one letter at a time with the contents of all the necessary lines.

  function sendEmail02() {
  var ss = SpreadsheetApp.openById(sheetID);
  var ActiveSheet = ss.getSheetByName("Sheet1");
  if (ActiveSheet.getName() == 'Sheet1')  {
  var StartRow = 2;
  var RowRange = ActiveSheet.getLastRow() - StartRow + 1;
  var WholeRange = ActiveSheet.getRange(StartRow,1,RowRange,3);
  var AllValues = WholeRange.getValues();

  var message = "";
  for (i in AllValues) {

  var CurrentRow = AllValues[i];

  if (CurrentRow[0] == "sent" && CurrentRow[1] != ""&& CurrentRow[2] != "") {

    message +=
    "<p><b>