As mentioned, I am hitting a road block in getting a simple script in google apps script to work properly. Essentially, I need to create an email draft with ~60 recipients - Google only allows up to 50 recipients to my knowledge (via using an apps script). Are there any work arounds for this within the apps script? Here is a link to the quotas: https://developers.google.com/apps-script/guides/services/quotas . My code below if that helps.
function doGet() {
createDraft();
return;
}
// this function grabs the correct emails from the google doc, outputs them separated by commas
function getEmails() {
const documentID = 'MY_DOCUMENT_ID';
const recipients = DocumentApp.openById(documentID).getBody().getText().split(/\n/).join(',');
Logger.log(recipients);
return recipients;
}
// this creates the email draft with the list of recipients
function createDraft() {
GmailApp.createDraft(getEmails(), 'SUBJECT', 'BODY TEXT');
}
And I receive this message after running:
Error - - - - - - Exception: Limit Exceeded: Email Recipients Per Message
So I'm pretty confident I am doing it right, and not confident that there is a solution, but if anyone knows any work arounds for this type of thing I would really appreciate it!
Thanks!
CodePudding user response:
How about this:
function getEmails() {
const documentID = 'MY_DOCUMENT_ID';
const recipients = DocumentApp.openById(documentID).getBody().getText().split(/\n/);
Logger.log(recipients);
return recipients;
}
// this creates the email draft with the list of recipients
function createDraft() {
const r = getEmails();
GmailApp.createDraft(r.slice(0,50).join(','), 'SUBJECT', 'BODY TEXT');
//may need some Utilities.sleep() in here dont know
GmailApp.createDraft(r.slice(50).join(','), 'SUBJECT', 'BODY TEXT');
}
CodePudding user response:
Apps Script services have daily quotas and limitations on some features to prevent abuse of the services.
Two workarounds that I could suggest:
- Breaking the recipient list just like @Cooper answered. With this option, keep in mind that the mail recipients quota per day is 100 for Gmail accounts.
- Add recipients to a group and send the email to the group email address instead.