3
votes

I'm a teacher and new to AppScript. I have created a spreadsheet to automatically send feedback to students via gmail from a google spreadsheet. It does work and the emails get sent from the spreadsheet but I get the following error 'Invalid Email <>' on the spreadsheet.

If anybody could help it'd be much appreciated.

function onOpen() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  var menu = [{
    name: "Send Email",
    functionName: "uiSendEmail"
  }];

  ss.addMenu("Send Email", menu);
}

function uiSendEmail() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  var range = sheet.getDataRange();
  range = range.offset(1, 0, range.getNumRows()-1);

  range.getValues().forEach( function( recipient, index, data ){
    var msgHtml = "Hi " + recipient[0] + "," + "<p>" + "Atttitude to Learning Grade is: " + "<b><u>" + recipient[5] + "</b></u>" + "<p>" + "Feedback: " + recipient[6] + "<p>" + "Improvements to be made: " + recipient[7] + "<p>" + "Overall Grade: " + recipient[8];
    var subject = recipient[3] + " - Teacher Feedback";

    var msgPlain = msgHtml.replace(/(<([^>]+)>)/ig, ""); // clear html tags for plain mail
    GmailApp.sendEmail(recipient[0] + " " + recipient[1] + "<" + recipient[2] + ">", subject, msgPlain, { htmlBody: msgHtml });
  });
}
1

1 Answers

1
votes

This was from long ago, so I assume you figured something out... (I stumbled upon this trying to solve a related problem).

From your above code and the error, I can see the that the recipient array contains no data.