I'm sending emails using google appscript I had 1500 DailyQuata before I executed my code once which send 3 emails, but my Daily quota becomes 1485 afterward. as I sent 3 emails it should have only gone down by 3
Daily Quota limit showing 1485
My spreadsheet is as follows
google Spreedsheet
entire code
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");
}
}
I have checked the value of last_row it 4 so the loop runs only 3 times.
edit: I used sendFormToAll() function to send emails
As indicated in this post How do I get the remaining daily mail quota of google apps scripts service to work consistently?, and in many other Issue Tracker requests in the comments:
It is an internal behavior in Apps Script and thus it is expected.
If somehow, this impacts your workflow, you could try checking your quota at least one hour after sending emails to stabilize the values.