0

I want to send a confirmation email whenever a customer submit a booking via google form. The content of the email will be partly based on the number of people and timeslot the customer chosen. I succeed in triggering an email, but the email content is [object Object]. What did i do wrong?

function sendBookingConfirmationEmail(e) {

  var html = HtmlService.createTemplateFromFile("confirmationEmail.html");
  var emailTo = e.response.getRespondentEmail();
  var bookingParameters = e.response.getItemResponses();

  var bookingName = bookingParameters[0].getResponse()
  var numberOfTele = bookingParameters[1].getResponse()
  var numberOfKids = bookingParameters[2].getResponse()
  var numberOfAdults = bookingParameters[3].getResponse()
  var scheduledSlot = bookingParameters[4].getResponse()

  html.numberOfKids = numberOfKids;
  html.numberOfAdults = numberOfAdults;
  html.numberOfTele = numberOfTele;
  html.scheduledSlot = scheduledSlot;

  var htmlText = html.evaluate().getContent();

  var emailSubject = "BOOKING CONFIRMATION";
  var options = { htmlBody: htmlText }

  if (emailTo !== undefined) {
    GmailApp.sendEmail(emailTo, emailSubject, options);

  }

}


<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <p>  <?= numberOfKids ?> <?= numberOfAdults ?> Your booking has been confirmed.  etc...</p>

    <p> Best Regards<br>
    Team</p>


  </body>
</html>
Gaspar Lam
  • 47
  • 6

2 Answers2

1

Based on this thread, try changing this line

GmailApp.sendEmail(emailTo, emailSubject, options);

to

GmailApp.sendEmail(emailTo, emailSubject, "", options);

I tested it and it works.

Lorena Gomez
  • 1,946
  • 2
  • 4
  • 11
0

from documentation ,the full signature for the function is the folowing :

sendEmail(recipient, subject, body, options)

I supsect that you pass the options variable as the body

As workaround, you can put every argument into an object :

sendEmail({recipient:emailTo , subject: emailSubject, htmlBody: htmlText})

  • It seems doesnt work, Exception: The parameters (String) don't match the method signature for GmailApp.sendEmail. at sendBookingConfirmationEmail(Code:25:14). I changed my code as follow `if (emailTo !== undefined) {GmailApp.sendEmail({recipient:emailTo, subject: emailSubject, htmlBody: htmlText})` – Gaspar Lam Oct 11 '22 at 14:22
  • damn ! if you usie `JSON.stringify(htmlTExt)` – Puygrenier Solann Oct 11 '22 at 14:48
  • `var htmlText = html.evaluate().getContent(); var newText = JSON.stringify(htmlText) if (emailTo !== undefined) { GmailApp.sendEmail({recipient:emailTo, subject: emailSubject, htmlBody: newText})` still doesnt work – Gaspar Lam Oct 11 '22 at 14:57
  • Sorry, and with : GmailApp.sendEmail({recipient:emailTo, subject: emailSubject, body:"", htmlBody: htmlText}) – Puygrenier Solann Oct 11 '22 at 15:16
  • Thank you for your prompt reply but sorry still doesnt work – Gaspar Lam Oct 11 '22 at 15:40
  • Okay then with a consol.log(htmlText) what do you got ? – Puygrenier Solann Oct 11 '22 at 15:44