How do I send an email to a submitted address with Apps Script upon a new form submission?

Viewed 22

I'm very new to development and was tasked with creating a confirmation email for anyone who enters their email into a waitlist form on a website. So far, I have been able to port an email address from the form to a Google Sheet but I have been unsuccessful in actually contacting said email.

My sheet format looks like this:

[Google Sheet Layout][1]

My dysfunctional code is:

function sendMail() {
  var ws = SpreadsheetApp.getActiveSheet();
  if (ws.getSheetName() != "Waitlist") return;
  var date = 0;
  var email = 1;
  
  var emailTemp = {};
  var emailTemp = HtmlService.createTemplateFromFile("email");
  var data = ws.getRange("A2:C" + ws.getLastRow()).getValues();
  var ranges = data.map(function (row, i) {
    if (row[1] == true && row[2] != "sent") {
      // emailTemp.date = row[date];
      var htmlMessage = emailTemp.evaluate().getContent();
      GmailApp.sendEmail(row[email],
        "Failure message",
        "Please submit again.",
        { name: "Fervo", htmlBody: htmlMessage }
      );
      return "C" + (i + 2);
    }
    return "";
  }).filter(String);
  ws.getRangeList(ranges).setValue("sent");
}

Apologies if it's completely wrong! I'd be super appreciative of some insight on how to make it spin. Thank you!

0 Answers
Related