每次提交表单(来自GoogleForms)时,尝试让Google的MailApp向我发送个人报告,一切正常,只是MailApp.sendmail()不断向我发送超过一百次的报告,直到每日配额饱和为止。下面你会找到我的主要代码(中和敏感数据)。有人可以帮我理解(并最好解决)这个问题吗?如果这是一个错误,我该如何为它提交错误报告?
// [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("EXAMPLE@gmail.com",
form.getTitle(),
message, {
name: ADDON_TITLE,
htmlBody: message
});
}
答案 0 :(得分:1)
您是否尝试过更换:
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("EXAMPLE@gmail.com",
form.getTitle(),
message, {
name: ADDON_TITLE,
htmlBody: message
});
使用电子邮件示例脚本(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: "recipient@example.com",
subject: "Logos",
htmlBody: "inline Google Logo<img src='cid:googleLogo'> images! <br>" +
"inline YouTube Logo <img src='cid:youtubeLogo'>",
inlineImages:
{
googleLogo: googleLogoBlob,
youtubeLogo: youtubeLogoBlob
}
});
}