google-apps-scriptgoogle-sheetsgoogle-formsapp-inventor

Google App Script: Create a list manually


I am trying to create a list of email recipients instead of just one recipient. Then send the email to all these recipients through app inventor. How do I do it? The code below send to only one recipient

function contactUsMailer(e) {
try {
var recipient = "example@gmail.com "
var timestamp = e.values[0];
var name = e.values[1];
var email = e.values[2];
var message = e.values[3];
var body = name+' <'+email+'> sent the following message: '+message;
var bodyHTML1 = '<p>'+name+' <a href="mailto:'+email+'">'+email+'</a> sent the following message: </p>';
var bodyHTML2 = '<blockquote>'+message+'</blockquote>';
var bodyHTML3 = '<p>Sent by the Pura Vida Apps <a href="http://www.puravidaapps.com/sendmailGS.php">Send Mail example</a>.</p>';
var advancedArgs = {htmlBody:bodyHTML1+bodyHTML2+bodyHTML3 , replyTo:email};
MailApp.sendEmail(recipient, "Contact Us Form", body, advancedArgs);
} 
catch(e){
MailApp.sendEmail(recipient, "Error - Contact Us Form", e.message);
  }
}  

Solution

  • Just comma-separate them

    var recipient = "example@gmail.com, example2@gmail.com, example3@gmail.com";
    

    If you have them in array it might be like

    var emails = ["example@gmail.com", "example2@gmail.com", "example3@gmail.com"];
    var recipient = emails.join(',');