简体   繁体   English

根据 2 个条件发送 2 封不同的电子邮件

[英]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.

相关问题 将带有不同 PDF 的电子邮件发送到不同的电子邮件附件 - send email with different PDFs to different emails attachment 自动发送来自不同发件人的电子邮件 - Automated Send emails from different sender 使用“函数sendMail()”发送2个不同的电子邮件 - Send 2 different emails using 'function sendMail()' 如果/其他声明无法发送其他电子邮件 - If/Else Statement not working to send different emails 有没有一种方法可以使用 nodemailer 向不同的人发送不同的电子邮件? - Is there a way one can send different emails to different people using nodemailer? 根据条件 - Wordpress表单向多个收件人发送单独的电子邮件 - Send separate emails to multiple recipients based on a condition - Wordpress form 根据条件执行不同的功能,而无需if语句 - Execute different functions based on conditions without if statements JavaScript根据不同条件显示分数和消息 - JavaScript displaying scores & messages based on different conditions 根据多种条件处理具有不同颜色的文本 - Manipulate text with different colors based on multiple conditions 如何根据 3 个不同的条件进行过滤(ReactJS) - How to filter based on 3 different conditions (ReactJS)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM