Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Apps Script: Multiple recipients in GmailApp?

Can I email multiple recipients through GmailApp.sendEmail()? I've tried storing the recipient addresses as an array, but it doesn't seem to send any of them.

Thanks!

like image 662
Finn Smith Avatar asked Dec 11 '22 11:12

Finn Smith


1 Answers

Yes you can.

If you direct yourself towards the Google Apps Spreadsheet services, you can see under the Gmail method that there are advanced parameters. GmailApp Services

It can look something like this.

GmailApp.sendEmail(recipient, subject, message, {cc: "[email protected],[email protected]"});

I never liked that way, and if I was sending to a varying number of people, and wanted to send them each an email instead of it being one big CC, the work around I found was this:

var emails = ["[email protected]","[email protected]","[email protected]"];
for (var i = 0; i < emails.length; i++) {
  GmailApp.sendEmail(emails[i], subject, message);
}

This way you can just simply edit the emails array by adding/subtracting an email and never having to change the actual code that sends the email. Only downside is it sends out X number of emails based on how many addresses you have in the array (if you're worried about hitting the daily cap), but it works none the less.

like image 86
Nick Avatar answered Dec 28 '22 05:12

Nick