Reputation: 1
I'm encountering the "Service invoked too many times for one day: email" error in my Google Apps Script when trying to send emails. I've read about the daily email sending limits, but I'm looking for solutions or best practices to overcome this issue.
Are there any recommended strategies to efficiently send a large number of emails using Google Apps Script without hitting this limit?
Is it advisable to switch to the Gmail API for higher email sending limits, and if so, how can I set it up within my script?
Are there any alternative approaches or workarounds to sending emails in Google Apps Script that don't have these limitations?
I appreciate any insights or guidance on resolving this issue. Thank you!
The sendEmails program is a Google Apps Script script used to send emails based on data stored in a Google Sheet. Here's a concise breakdown of how it works:
Variable Setup: The program begins by setting up several variables, such as the message, subject, Google Drive folder ID, and the file name to track sent emails.
Fetching Data from Google Sheet: It retrieves data from the current sheet of the Google Sheet, including email addresses (child and parent), scores, and other data.
Checking and Sending Emails: The program iterates through the rows of data and checks if a score ends with "+". If the condition is met, it verifies whether an email has already been sent to the email addresses (both email1 and email2). If an email has already been sent, it won't resend.
Sending Emails: Depending on the presence of email addresses (email1 and email2), the program sends an email to the child, the parent, or both. After sending an email, the email address is added to the sent_emails.txt file to prevent duplicate sending.
In summary, the program automates the sending of congratulatory emails based on data in a Google Sheet while considering limitations on email sending in Google Apps Script and avoiding duplicate emails to the same addresses.
my code:
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var data = sheet.getDataRange().getValues();
var message = "Здравствуйте, вы получили плюс!";
var subject = "Поздравляем!";
var folderId = '19CAHVoMPr8mKlZumZ9mRXBF9VIL3woPy';
var fileName = "sent_emails.txt";
var folder = DriveApp.getFolderById(folderId);
var file;
try {
file = folder.getFilesByName(fileName).next();
} catch (e) {
file = folder.createFile(fileName, '');
}
var sentEmails = file.getBlob().getDataAsString().split('\n');
for (var i = 1; i < data.length; i++) {
var email1 = data[i][16];
var email2 = data[i][17];
var score = String(data[i][7]);
if (score.match(/\+$/) && (!sentEmails.includes(email1) || !sentEmails.includes(email2))) {
if (email1 && email2) {
GmailApp.sendEmail([email1, email2], subject, message);
file.setContent(file.getBlob().getDataAsString() + email1 + '\n'+ email2 + '\n');
} else if (email1) {
GmailApp.sendEmail(email1, subject, message);
file.setContent(file.getBlob().getDataAsString() + email1 + '\n');
} else if (email2) {
GmailApp.sendEmail(email2, subject, message);
file.setContent(file.getBlob().getDataAsString() + email2 + '\n');
}
}
}
}
Upvotes: 0
Views: 1073
Reputation: 1
I have a paid google workspace business starter account. I believe the quota for mail merge is 1500 emails per day. I however got the service invoked. Using the Appscript mail merge.
Upvotes: -1