简体   繁体   中英

Send Email to Multiple Addresses in Google Spreadsheet

I have constructed a script which sends some data to addresses in cell "B" a spreadsheet sheet named "Email". Currently, it seems to only send to one email address. I want it to be able to send to multiple addresses within the same cell, which would be separated by a comma. Hopefully, this makes sense. I appreciate your help with this! Here is my current code for fetching the email address:

var email = ''; // If we don't find a match, we'll fail the send
  for (var row=0; row < names.length; row++) {
  if (names[row][0] == recipient) {
  email = emails[row][0];
  break; // end the search, we're done
 }
}

Both GmailApp & MailApp support sending to multiple email addresses, where the addresses are a comma-delimited string. I've tried both, using 3 different addresses on different services (hotmail, yahoo, private), and they worked fine for me.

While we may not know why this isn't working for you, you could try this work-around. It just breaks the string of addresses up into an array, then sends a separate email for each element. (Con: this will increase your email-per-day count unnecessarily.)

var emailArray = email.split(",");
emailArray.forEach( function (address) {
  MailApp.sendEmail(address,subject,message);
});

If you're not into the use of forEach() , this is equivalent:

var emailArray = email.split(",");
for (var i=0; i<emailArray.length; i++) {
  MailApp.sendEmail(emailArray[i],subject,message);
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM