Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

javascript - How do I get the remaining daily mail quota of google apps scripts service to work consistently?

I did a project on google apps scripts to send automatic emails after a form response was sent. However, when I check the daily quota of remaining emails with the MailApp.getRemainingDailyQuota() method, the quota responses vary with each script execution.

So I created another project just to test the quota, using the MailApp.getRemainingDailyQuota() method and even so, the quota response varied with each execution.


Code used to test:

function testeDeCota() { 
  let cota;

  cota = MailApp.getRemainingDailyQuota();
  Logger.log("Cota de emails restantes: " + cota);

  cota = MailApp.getRemainingDailyQuota();
  Logger.log("Cota de emails restantes: " + cota);

}

I am using a workspace account that has a quota of 1500 emails/day.

This is a screeshot of my executions. Note that there are 3 consecutive executions and without sending any email, even so the quota responses varied. The responses were:

1394; 1399; 1390.

Whenever I try to send an email or get the quota information the number just varies randomly.

printscreen of the script executions

question from:https://stackoverflow.com/questions/65925982/how-do-i-get-the-remaining-daily-mail-quota-of-google-apps-scripts-service-to-wo

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This seems to be intended behavior.

Apart from the older issue Marios mentioned (Gmail SendEmail Quota - Decrementing Bug/issue), this was reported recently in Issue Tracker, and closed as Intended Behaviour:

See comments #6 and #8:

This small fluctuation in the value returned by this method is to be expected.

This behaviour is caused by how quotas are internally handled by Apps Script. It's expected behaviour.

Different executions vs Loop:

Interestingly, this discrepancy can only be seen when calling this method in separate invocations. When calling this method in a loop instead, no fluctuation is shown:

for(i=1; i<=n; i++) {
  SpreadsheetApp.openById(documentID).getSheetByName(sheetName).appendRow([new Date(), MailApp.getRemainingDailyQuota()]);
  Utilities.sleep(1000);
}

File a feature request:

As suggested in the referenced issue, if this is impacting your workflow somehow, you could consider filing a feature request.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...