Reputation: 21
Trying to get Google's MailApp sending me an individual report each time a form (from GoogleForms) is submitted, everything works fine except that MailApp.sendmail() keeps sending me over a hundred times that report until saturation of the daily quota. Hereunder will you find my main code (with sensitive data neutralised). Can someone please help me understand (and preferably solve) that issue ? If this is a bug, how can I submit a bug report for it ?
// [this function has been set only once as an "onFormSubmit" trigger][1]
function computeReport(e) {
var form = FormApp.getActiveForm();
var formResponses = form.getResponses();
// compute for last response only (anyway it has only one response so far, for devel purposes)
var formResponse = formResponses[formResponses.length - 1];
var itemResponses = formResponse.getItemResponses();
var template = HtmlService.createTemplateFromFile('Report');
template.title = form.getTitle();
template.formUrl = form.getEditUrl();
// each of the 6 following subroutines calls Logger.log() to tell it has been called
gatherRespondentData(itemResponses, template);
computeTest1(itemResponses, formResponse, template);
computeTest2(itemResponses, formResponse, template);
computeTest3(itemResponses, formResponse, template);
computeTest4(itemResponses, formResponse, template);
computeTest5(itemResponses, formResponse, template);
// they all do their job perfectly and are irrelevant to this issue
form.submitGrades(formResponses);
template.responses = form.getEditUrl() + "#response=" + formResponse.getId();
template.respondentEmail = formResponse.getRespondentEmail();
var message = template.evaluate().getContent();
Logger.log("Send e-mail"); // [as well as other calls to it, this is called just once][2]
// and so should theoretically be the following,
// but MailApp keeps sending it to me over a hundred times until saturation of the daily quota
MailApp.sendEmail("[email protected]",
form.getTitle(),
message, {
name: ADDON_TITLE,
htmlBody: message
});
}
Upvotes: 2
Views: 68
Reputation: 1595
Have you tried to replace your:
Logger.log("Send e-mail"); // [as well as other calls to it, this is called just once][2]
// and so should theoretically be the following,
// but MailApp keeps sending it to me over a hundred times until saturation of the daily quota
MailApp.sendEmail("[email protected]",
form.getTitle(),
message, {
name: ADDON_TITLE,
htmlBody: message
});
With an email example script (https://developers.google.com/apps-script/reference/mail/mail-app):
// This code fetches the Google and YouTube logos, inlines them in an email
// and sends the email
function inlineImage() {
var googleLogoUrl = "http://www.google.com/intl/en_com/images/srpr/logo3w.png";
var youtubeLogoUrl =
"https://developers.google.com/youtube/images/YouTube_logo_standard_white.png";
var googleLogoBlob = UrlFetchApp
.fetch(googleLogoUrl)
.getBlob()
.setName("googleLogoBlob");
var youtubeLogoBlob = UrlFetchApp
.fetch(youtubeLogoUrl)
.getBlob()
.setName("youtubeLogoBlob");
MailApp.sendEmail({
to: "[email protected]",
subject: "Logos",
htmlBody: "inline Google Logo<img src='cid:googleLogo'> images! <br>" +
"inline YouTube Logo <img src='cid:youtubeLogo'>",
inlineImages:
{
googleLogo: googleLogoBlob,
youtubeLogo: youtubeLogoBlob
}
});
}
Upvotes: 1