I have a google apps script developed for when a user submits a form. Its an app script from the spreadsheet attached to form responses. In the script I send back an acknowledgement email. Just recently, I have started receiving some error message from Google Script (on some, but not all responses):
Your script, blahblahblah, has recently failed to finish successfully. A summary of the failure(s) is shown below. To configure the triggers for this script, or change your setting for receiving future failure notifications, click here.
Start: 5/21/19 4:57 PM
Function: sendResponseToPlayer
Error Message: Failed to send email: no recipient (line 97, file "blahblahblah")
Trigger: formSubmit
End: 5/21/19 4:57 PM
Sincerely,
Google Apps Script
Also recognize:
- that in my "Sent Mail" box, there is an email sent to the respondent that the script sends email to.
- the recipient did not receive the email
- the script has not changed in the past 4 weeks
- the file attachments have not changed in the past 4 weeks
- the error is now occurring with each form respondent
Why would these errors start creeping up? Why would I get the email in my Sent Mail box if there was an error? What do I need to change in the script?
Thanks in advance for any insight provided.
function sendResponseToPlayer(e) {
var values = e.namedValues;
var pfname = values['First Name'].toString();
var plname = values['Last Name'].toString();
var pyn = values['Playing?'].toString();
var pem = values['Email Address'].toString();
// Acknowledge their response
var subject = 'Player Response ';
var hbody = '';
hbody += "<p>Thank you, " + pfname + ". You have answered \"" + pyn + "\" to playing this week.</p>";
// Add document text
var body = DocumentApp.openByUrl('https://docs.google.com/document/d/123abc/edit').getBody();
var bodyTextElement = body.editAsText();
var bodyString = bodyTextElement.getText();
hbody += "<p>" + bodyString + "</p>";
// Add spreadsheet text
var sheet = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123/edit#gid=0');
var values = sheet.getActiveSheet().getDataRange().getDisplayValues();
for (var i = 0; i < values.length; i++) { // length of first dimension of 2d array
for (var j = 0; j < values[i].length; j++) { // length of dimension of specific row
hbody += values[i][j] + " ";
}
hbody += "<br>";
}
hbody += "<p>Please see attachments.</p>";
var fid = '789xyz';
var file = DriveApp.getFileById(fid);
var fcal = 'xyz789';
var calfile = DriveApp.getFileById(fcal);
var replem = 'me@gmail.com';
MailApp.sendEmail({
to: pem,
replyTo: replem,
subject: subject,
htmlBody: hbody,
attachments: [file.getAs(MimeType.PDF),calfile.getAs(MimeType.PDF)],
name: 'me'
});
}