Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

287
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda