繁体   English   中英

谷歌应用程序脚本sendEmail发送多封电子邮件

[英]google apps script sendEmail sending multiple emails

免责声明:我是Stack Overflow的新手,我不是开发人员。

我在IT部门工作,目前我们正在尝试将所有纸质/电子表格转换为Google表格。 我目前正在尝试编写一个脚本(见下文),该脚本将根据其中一个答案向特定人员发送电子邮件。 好消息是脚本有效(woot!)。

我遇到的问题是,当我测试它时,我会收到2到3个确切的电子邮件。 使用我的Gmail帐户尤其糟糕。

如果以下代码看起来很残酷,我愿意接受建议! 先谢谢您的帮助!!

function myFunction() {
var form = FormApp.getActiveForm()

var formResponses = form.getResponses();

for (var i = 0; i < formResponses.length; i++) {
 var formResponse = formResponses[i];
 var itemResponses = formResponse.getItemResponses();
 var work = itemResponses[3];
 var problem = itemResponses[2].getResponse();
 var location = itemResponses[4].getResponse();
 var name = itemResponses[0].getResponse()
 var sheetsLink = docs.google.com/sheetid
}

if (work.getResponse() === "Food Services") {
  MailApp.sendEmail('mymail@gmail.com', 'Kitchen Maintenance', name + ' has a problem with ' + problem + ' in the kitchen at ' + location + '.  More information for this request can be found at: ' + sheetsLink + '.');                    

} else {
  MailApp.sendEmail('mymail@schoolacct', 'Maintenance', name + ' has a problem with ' + problem + ' at ' + location + '.  More information for this request can be found at: ' + sheetsLink + '.');
 } 
}

您可以更轻松地将表单响应保存在电子表格中,然后使用表单提交触发器将应用程序脚本绑定到电子表格。 这将允许您在电子表格中记录所有表单响应,如果出现任何问题,您可以随时重新检查。 在发送的多封电子邮件中,需要检查多个编辑器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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