這個問題在這里已經有了答案: 如何讓谷歌應用程式腳本服務的剩余每日郵件配額始終如一地作業? (1 個回答) 6 天前關閉。
我正在使用 google appscript 發送電子郵件,在我執行一次發送 3 封電子郵件的代碼之前,我有 1500 DailyQuata,但之后我的每日配額變為 1485。因為我發送了 3 封電子郵件,它應該只下降了 3
每日配額限制顯示 1485![當我只使用 appscript MailApp 發送 3 封電子郵件時,為什么我的 DailyQuota for Gmail 下降了 15?[復制]](https://img.uj5u.com/2021/10/21/98d5e5b1330c44c8a16367f9599c9075.png)
我的電子表格如下谷歌電子表格![當我只使用 appscript MailApp 發送 3 封電子郵件時,為什么我的 DailyQuota for Gmail 下降了 15?[復制]](https://img.uj5u.com/2021/10/21/2f7cc5789b5f448093fac7b3b6bdc9f4.png)
完整代碼
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Automation')
.addItem('send PDF Form', 'sendPDFForm')
.addItem('send to all', 'sendFormToAll')
.addToUi();
console.log(MailApp.getRemainingDailyQuota())
}
function sendPDFForm() {
var row = SpreadsheetApp.getActiveSheet().getActiveCell().getRow();
sendEmailWithAttachment(row);
}
function sendEmailWithAttachment(row) {
var client = getClientInfo(row);
var file = DriveApp.getFilesByName(client.filename);
if (!file.hasNext()) {
console.error("Could not open file " client.filename);
return;
}
var template = HtmlService.createTemplateFromFile('email-template');
template.client = client;
var message = template.evaluate().getContent();
MailApp.sendEmail({
to: client.email,
subject: "Engineer's Day participation Certificate",
htmlBody: message,
attachments: [file.next().getAs(MimeType.JPEG)]
});
}
function getClientInfo(row) {
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
var values = sheet.getRange(row, 1, 1, 5).getValues();
var rec = values[0];
console.log(rec)
var client ={filename: rec[4],name: rec[1],first_name: rec[2],email: rec[3]};
return client;
}
function sendFormToAll() {
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
var last_row = sheet.getDataRange().getLastRow();
console.log(last_row)
for (var row = 2; row <= last_row; row ) {
sendEmailWithAttachment(row); //sending email
Utilities.sleep(300);
sheet.getRange(row, 7).setValue("email sent");
}
}
我已經檢查了 last_row it 4 的值,所以回圈只運行了 3 次。
編輯:我使用 sendFormToAll() 函式發送電子郵件
uj5u.com熱心網友回復:
如這篇文章中所述,我如何使 google 應用程式腳本服務的剩余每日郵件配額始終如一地作業?,以及在評論中的許多其他問題跟蹤器請求中:
這是預期的行為。
這是 Apps 腳本中的內部行為,因此是意料之中的。
如果不知何故,這會影響您的作業流程,您可以嘗試在發送電子郵件后至少一小時檢查您的配額以穩定值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/327422.html
標籤:javascript 谷歌应用程序脚本 谷歌表格 邮箱 配额
