Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

271
Views
I wrote a code to send 1 general email and 1 conditional email, but the conditional email isn't sending

I want to send 1 general email and 1 conditional email (based on whether the response to a particular question was 'yes' or 'no') upon form submit. I have no issues with the general email being sent, but when I select the 'yes' option in the Google Form, the conditional email isn't sending. Here is the code I have so far (and I have also set up the relevant triggers for sendEmail and sendConditionalEmail). Any advice is appreciated!

function sendEmail(e) {
  var html = HtmlService.createTemplateFromFile("GeneralEmail.html");
  var htmlText = html.evaluate().getContent();
  var emailTo = e.response.getRespondentEmail();
  Logger.log(emailTo);
  var subjectofEmail = "TESTING INFORMATION (BRJ)";
  var textBody = "This email requires HTML support";
  var options = {htmlBody: htmlText};
  if(emailTo !== undefined){
    MailApp.sendEmail(emailTo, subjectofEmail, textBody, options);
  } 
}

function sendConditionalEmail(e){
var Conditionalhtml = HtmlService.createTemplateFromFile("ConditionalEmail.html");
var ConditionalhtmlText = Conditionalhtml.evaluate().getContent();
var subjectOfEmail = "Guided Testing (BRJ)";
var textBody = "This email requires HTML support";
var interested = objectifyingFormforInterested();
var emailTo = e.response.getRespondentEmail();
Logger.log(interested);
if (interested == "Yes") {
  MailApp.sendEmail( emailTo, subjectOfEmail,'', {
    htmlBody: ConditionalhtmlText, 
    cc: 'xxx@gmail.com'});
}
}

function objectifyingFormforInterested(myForm){
var myForm = FormApp.openById("13o_WK3G8m6PeopBrI2y6p6SrNp-cGFs3vgpRdqotISY");
var formResponses = myForm.getResponses();
Logger.log(formResponses);
var currentResponse = formResponses[formResponses.length-1];
var responseArray = currentResponse.getItemResponses();
Logger.log(responseArray);
var form= {};
form.user = currentResponse.getRespondentEmail();
form.timestamp = currentResponse.getTimestamp();
form.formName = myForm.getTitle();
var response = responseArray[responseArray.length-1].getResponse();
Logger.log(response);
return response;
}

function camelize(str) {
  str = str.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()@\+\?><\[\]\+]/g, '')
  return str.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function(match, index) {
    if (+match === 0) return ""; // or if (/\s+/.test(match)) for white spaces
    return index == 0 ? match.toLowerCase() : match.toUpperCase();
  });
}
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Address Comments below and perhaps you can get it to work properly

function sendConditionalEmail(e) {
  var Conditionalhtml = HtmlService.createTemplateFromFile("ConditionalEmail.html");
  var ConditionalhtmlText = Conditionalhtml.evaluate().getContent();
  var subjectOfEmail = "Guided Testing (BRJ)"
  var interested = objectifyingFormforInterested();//You are not passing the MyForm parameter to this function
  var emailTo = e.response.getRespondentEmail();
  if (interested == "Yes") {
    MailApp.sendEmail(emailTo, subjectOfEmail, null, {
      htmlBody: ConditionalhtmlText,
      cc: 'xxx@gmail.com'
    });
  }
}

function objectifyingFormforInterested(myForm) {
  var myForm = FormApp.openById("13o_WK3G8m6PeopBrI2y6p6SrNp-cGFs3vgpRdqotISY");
  var formResponses = myForm.getResponses();
  var currentResponse = formResponses[formResponses.length - 1];
  var responseArray = currentResponse.getItemResponses();
  var form = {};
  form.user = currentResponse.getRespondentEmail();
  form.timestamp = currentResponse.getTimestamp();
  form.formName = myForm.getTitle();
  var response = responseArray[responseArray.length - 1].getResponse();
  return response;
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!