4
votes

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!

3
All right, seems to have just been a delay in sending, maybe related to this.mrfinnsmith

3 Answers

7
votes

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.

5
votes

The recipient argument takes a string, so you can simply write your multiple recipients as a string with a comma in between:

GmailApp.sendEmail('[email protected], [email protected]', ...); 

Should work. Note that they will all see each other as recipients.

Edit: I tried it and it works.

0
votes

When I have multiple addresses, I just reference the list via a range. The below script sample would send to 5 email addresses pulled from C2:C6 on the sheet/tab named Email.

    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var emailRange = ss.getSheetByName("Email").getRange(2,3,5,1);
    var emailAddress = emailRange.getValues();
      Logger.log(emailAddress);
    var message = 'Message you wish to enter';
    var subject = 'Verbiage for Subject Line';
   GmailApp.sendEmail(emailAddress, subject, message)