要重现该错误,请为send_email()创建一个onEdit触发器。
var ss = SpreadsheetApp.getActiveSheet();
var cell = ss.getActiveCell();
var range = SpreadsheetApp.getActiveRange();
var row = range.getRow();
var emailQuotaRemaining = MailApp.getRemainingDailyQuota();
function send_email(){
GmailApp.sendEmail('my_address@yahoo.com','Subject','Body');
ss.getRange(row,2).setValue("You have " +emailQuotaRemaining+' emails left');
}
您不会收到重复的电子邮件,但配额有时会减少2,在极少数情况下会减少3或4。
连续几次输入1,2,3之后,显然减少了混乱,并且一旦触发了sendemail功能。更重要的是,我只收到了14封电子邮件,而不是19封。
对于上面的代码,表格如下:
1 You have 95 emails left
2 You have 92 emails left
3 You have 94 emails left
1 You have 91 emails left
2 You have 90 emails left
3 You have 89 emails left
1 You have 89 emails left
2 You have 88 emails left
3
1 You have 86 emails left
2 You have 85 emails left
3 You have 85 emails left
1 You have 85 emails left
2 You have 85 emails left
3 You have 84 emails left
1 You have 83 emails left
2 You have 82 emails left
3 You have 80 emails left
对此有何解决方法?
答案 0 :(得分:0)
导致问题的不只是MailApp.getRemainingDailyQuota()
;或者它可能是可安装触发器的问题。我用以下代码重现了这个问题。以下代码可以正常工作,除非您快速编辑工作表。所以,我猜测Google的服务器存在延迟。
function sendEmail(e) {
var lockt = LockService.getScriptLock();
var ss = SpreadsheetApp.getActiveSheet();
var row = e.range.getRow();
ss.getRange(row,2).setValue("You have " +'99'+' emails left');
LockService.getScriptLock().releaseLock();
};