gpt4 book ai didi

javascript - 将电子邮件发送到多个地址的脚本

转载 作者:行者123 更新时间:2023-12-03 07:46:57 27 4
gpt4 key购买 nike

每当有人填写 Google 表格中的必填字段时,我都会使用 Google 表格发送自动预填写的电子邮件。如何使以下脚本根据用户输入的位置发送到不同的电子邮件?例如,如果用户输入伦敦,则发送电子邮件至 email1@email.com,或者如果用户输入巴黎,则发送电子邮件至 email2@email.com。另外,我是否需要为 Google 表格添加触发器才能知道何时启动此脚本?

function fireEmail(e){
var userName = e.values[1];
var timeStamp = e.values[0];
var medalType1 = e.values[2];
var medalType2 = e.values[3];
var medalColor = e.values[4];
var medalRecipient = e.values[5];
var dateNeeded = e.values[6];
var medalLocation = e.values[7];


var emailBodyHTML = [];
emailBodyHTML += '<b>You have received a medal request from ' + userName + '.</b>';
emailBodyHTML += '<p>Onboarding Ops Medal Type, If Applicable: ' + medalType1 + '</p>';
emailBodyHTML += '<p>Service Ops Medal Type, If Applicable: ' + medalType2 + '</p>';
emailBodyHTML += '<p>Medal Color: ' + medalColor + '</p>';
emailBodyHTML += '<p>Medal Recipient: ' + medalRecipient + '</p>';
emailBodyHTML += '<p>Medal Needed by: ' + dateNeeded + '</p>';
emailBodyHTML += '<p>Please visit <a href="place.com">the medaling document</a> to manage this request.</p>';

var emailSubject = 'New Medal Request for ' + medalLocation + '!';

MailApp.sendEmail({
to: "email1@email.com",
name: "Medaling Request",
subject: emailSubject,


htmlBody: emailBodyHTML
});

}

最佳答案

要检查位置,您可以使用 if-statement (在你的 html 正文之后)

var mailTo;
if (medalLocation == 'London') {
mailTo = 'abc@gmail.com';
} else if (medalLocation == 'Paris' {
mailTo = 'def@gmail.com';
}

如果您只有两个位置,也可以使用 conditional (ternary) operator :

var mailTo = (medalLocation == 'London') ? 'abc@gmail.com' : 'def@gmail.com'

另一方面,如果您有更多位置需要检查,我建议使用 switch statement

var mailTo;
switch(medalLocation) {
case 'London':
mailTo = 'abc@gmail.com';
break;
case 'Paris':
mailTo = 'def@gmail.com';
break;
case 'Brussels':
mailTo = 'ghi@gmail.com';
break;
default:
mailTo = 'jkl@gmail.com';
}

然后,确定“mailTo”后,将邮件部分更改为

 MailApp.sendEmail({
to: mailTo,
name: "Medaling Request",
subject: emailSubject
htmlBody: emailBodyHTML

});

脚本应该有一个表单提交触发器。希望这有帮助?

关于javascript - 将电子邮件发送到多个地址的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35167018/

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