Google Script: MailApp.sendEmail to multiple addresses?

匿名 (未验证) 提交于 2019-12-03 08:36:05

问题:

I have a script that is using the following script:

MailApp.sendEmail(row.shiftManager, "Holiday Approval Request", "", {htmlBody: message});   row.state = STATE_PENDING;

Howeverm I would like to also send the same mail to row.shiftSupervisor, this is probably something really simple that I've overlooked, but I figured someone here would know straight away what it was.

Cheers for your help :)

Edit - I tried to use:

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

But no joy.

Edit 2 - I got it working with:

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

Not the most graceful looking piece of code, but it does the job...

Edit 3 - After looking at Sandy's solution, I figured it was formatting. Sandy' solution works fine, but caused conflicts with some other parts of my script. So my solution was:

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

回答1:

One solution is to configure the syntax this way:

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

Another method is to put the multiple email addresses into a variable first, then use this syntax:

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

The complete code would be:

function sendToMultiple() {   var message = "This is a test of HTML <br><br> Line two";    var recipientsTO = "example@gmail.com" + "," + "example@yahoo.com";   var recipientsCC = "example@gmail.com";   var Subject = "Holiday Approval Request";   var html = message;    MailApp.sendEmail({     to: recipientsTO,     cc: recipientsCC,     subject: Subject,     htmlBody: html   });  }

That syntax is shown in an example at this link:

Google Documentation - MailApp.sendEmail



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!