Google Script: MailApp.sendEmail to multiple addresses?

后端 未结 2 1843
夕颜
夕颜 2021-01-04 02:14

I have a script that is using the following script:

MailApp.sendEmail(row.shiftManager, "Holiday Approval Request", "", {htmlBody: message         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-04 03:17

    The email addresses can be concatenated (joined together) using the plus sign with a comma in between each email address. In JavaScript the plus sign can be used for addition OR joining strings. The plus sign is both an addition operator and a string operator in JavaScript. Strings are text, and if you use the plus sign to concatenate text strings then it's a string formula.

    One solution would be:

    var recipient = row.shiftManager + "," + row.shiftSupervisor;
    MailApp.sendEmail(recipient, "Holiday Approval Request", "", {htmlBody: message});
    

    In the above example, there are 4 parameters. But MailApp.sendEmail() has multiple possible parameter structures. The following example shows all of the settings put into an object, where the "to" key in the object is for the recipient.

    MailApp.sendEmail({
      to: recipient,
      cc: recipientsCC,
      subject: Subject,
      htmlBody: html
    });
    

    A complete example:

    function sendToMultiple() {
      var message = "This is a test of HTML 

    Line two"; var recipientsTO = "example@gmail.com" + "," + "example@yahoo.com"; var recipientsCC = "example@gmail.com"; var Subject = "Vacation Approval Request"; var html = message; MailApp.sendEmail({ to: recipientsTO, cc: recipientsCC, subject: Subject, htmlBody: html }); }

    Documentation with an example is at the following link:

    Google Documentation - MailApp.sendEmail

提交回复
热议问题