[英]Send 2 different emails based on 2 conditions
So I'm trying out Apps Script and want my code to send an email based whether a condition is True or False.所以我正在尝试应用程序脚本,并希望我的代码根据条件是真还是假来发送 email。 I was able to execute and receive an email when the only conditional is True but I'm quite unsure how to add the else statement as seen below as an error sign appears once I save the script
当唯一的条件为 True 时,我能够执行并接收 email 但我很不确定如何添加 else 语句,如下所示,因为一旦我保存脚本就会出现错误标志
function sendMailEdit(e) {
const rData = e.source.getActiveSheet().getRange(e.range.rowStart, 1, 1, 15).getValues();
var paticipateTicket = rData[0][1];
var ticketType = rData[0][2];
var ticketNumber = rData[0][14];
var company = rData[0][3];
var name = rData[0][4];
var email = rData[0][5];
var remarks = rData[0][1];
if (e.range.columnStart != 17 || e.value != "Yes") return;{
var html = `<h2> Hello ${name} !</h2><p>Your purchase of a ${paticipateTicket} under ${company} is confirmed with ticket number ${ticketNumber}. <p>See you at the tournament at the details below.</p>
Your ticket number is ${ticketNumber} with a ticket type of and you'll be participating under ${company} </p><p><img src = "https://drive.google.com/uc?export=view&id=1nMiIfUgfFPYn4YOzXmEwJlaiNRPyOHsI" width = "200 px" length = "300 px"></p>`;
var msg = name + "Your payment has been verified. Your ticket number is " + ticketNumber + ".Participating under " + company
GmailApp.sendEmail(email, "2022 Charity Golf Tournament", msg, { htmlBody: html });
}
else (e.range.columnStart != 17 || e.value != "No") return;{
var html = `<h2> Hello ${name} !</h2><p>Your purchase of a ${paticipateTicket} under ${company} is has been paused and here’s why: </p> <p> ${remarks}</p>
var msg1 = name + "Your payment has been paused. Below is the reason why”
GmailApp.sendEmail(email, "2022 Charity Golf Tournament", msg, { htmlBody: html });
}
}
There were some missing characters and in one case the wrong " symbol was used, try replacing the if-else block with this:缺少一些字符,在一种情况下使用了错误的 " 符号,请尝试将 if-else 块替换为:
if (e.range.columnStart != 17 || e.value != "Yes"){
var html = `<h2> Hello ${name} !</h2><p>Your purchase of a ${paticipateTicket} under ${company} is confirmed with ticket number ${ticketNumber}. <p>See you at the tournament at the details below.</p>
Your ticket number is ${ticketNumber} with a ticket type of and you'll be participating under ${company} </p><p><img src = "https://drive.google.com/uc?export=view&id=1nMiIfUgfFPYn4YOzXmEwJlaiNRPyOHsI" width = "200 px" length = "300 px"></p>`;
var msg = name + "Your payment has been verified. Your ticket number is " + ticketNumber + ".Participating under " + company
GmailApp.sendEmail(email, "2022 Charity Golf Tournament", msg, { htmlBody: html });
} else if (e.range.columnStart != 17 || e.value != "No"){
var html = `<h2> Hello ${name} !</h2><p>Your purchase of a ${paticipateTicket} under ${company} is has been paused and here’s why: </p> <p> ${remarks}</p>`
var msg1 = name + "Your payment has been paused. Below is the reason why";
GmailApp.sendEmail(email, "2022 Charity Golf Tournament", msg1, { htmlBody: html });
}
Try it this way:试试这种方式:
function sendMailEdit(e) {
const sh = e.range.getSheet();
const [, paticipateTicket, ticketType, company, name, email, , , , , , , , , ticketNumber] = sh.getRange(e.range.rowStart, 1, 1, 15).getValues()[0];
if (e.range.columnStart == 17 && e.value == "Yes") {
var html = `<h2> Hello ${name} !</h2><p>Your purchase of a ${paticipateTicket} under ${company} is confirmed with ticket number ${ticketNumber}. <p>See you at the tournament at the details below.</p>
Your ticket number is ${ticketNumber} with a ticket type of and you'll be participating under ${company} </p><p><img src = "https://drive.google.com/uc?export=view&id=1nMiIfUgfFPYn4YOzXmEwJlaiNRPyOHsI" width = "200 px" length = "300 px"></p>`;
var msg = name + "Your payment has been verified. Your ticket number is " + ticketNumber + ".Participating under " + company
GmailApp.sendEmail(email, "2022 Charity Golf Tournament", msg, { htmlBody: html });
} else if (e.range.columnStart == 17 && e.value == "No") {
var html = `<h2> Hello ${name} !</h2><p>Your purchase of a ${paticipateTicket} under ${company} is has been paused and here’s why: </p> <p> ${remarks}</p>`;
var msg1 = name + "Your payment has been paused. Below is the reason why";
GmailApp.sendEmail(email, "2022 Charity Golf Tournament", msg1, { htmlBody: html });
}
}
remarks is undefined备注未定义
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.