gpt4 book ai didi

email - Google脚本:MailApp.sendEmail到多个地址?

转载 作者:行者123 更新时间:2023-12-04 03:07:15 26 4
gpt4 key购买 nike

我有一个使用以下脚本的脚本:

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


但是,我也想将相同的邮件发送到 row.shiftSupervisor,这可能是我忽略的非常简单的事情,但是我认为这里的某个人会立即知道它是什么。

为您的帮助加油:)

编辑-我尝试使用:

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


但是没有喜悦。

编辑2-我可以使用它:

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


不是看起来最优美的代码,但是它可以完成工作...

编辑3-看完Sandy的解决方案后,我认为它正在格式化。
Sandy的解决方案工作正常,但与脚本的其他部分产生了冲突。所以我的解决方案是:

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

最佳答案

可以使用加号将电子邮件地址串联(连接在一起),并在每个电子邮件地址之间使用撇号。在JavaScript中,加号可用于加法或连接字符串。加号在JavaScript中既是加法运算符又是字符串运算符。字符串是文本,如果您使用加号连接文本字符串,则它是一个字符串公式。

一种解决方案是:

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


在上面的示例中,有4个参数。但是 MailApp.sendEmail()具有多个可能的参数结构。下面的示例显示了放入对象的所有设置,其中对象中的“ to”键用于收件人。

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


一个完整的例子:

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 = "Vacation Approval Request";
var html = message;

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

}


带有示例的文档位于以下链接:

Google Documentation - MailApp.sendEmail

关于email - Google脚本:MailApp.sendEmail到多个地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28355195/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com