Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

284
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda