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

104
Visualizações
How to send a data array in one email without looping in google apps script?

I am writing an email function that is supposed to send an email from ALL the range data in the spreadsheet after clicking a button, the problem is I cannot get one email with all the data, instead, every email is sent individually through the loop, is there a way that I can have all data sent in as HTML data in one email? When I place var htmlMessage=emailTemp.evaluate().getContent(); outside the loop it triggers BarcodeT is not defined.

function email(){
  
  var Barcode=0;
  var Name=1;
  var Added=2;
  var Price=3;

  var emailTemp=HtmlService.createTemplateFromFile("Email");
  var ws=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Refill Request");
  var data = ws.getRange("A3:D" + ws.getLastRow()).getValues();
  

   let BarcodeT="";
   let NameT="";
   let AddedT="";
   let PriceT="";
  
  data.forEach(function(row){
    BarcodeT+=emailTemp.ItemCode=row[Barcode];
    NameT+=emailTemp.ItemName=row[Name];
    AddedT+=emailTemp.QuantityNeeded=row[Added];
    var htmlMessage=emailTemp.evaluate().getContent();

    })
            

    var address = "test@gmail.com";

    MailApp.sendEmail(address,"Refill Request","Your email doesn't support HTML.",
    {name: "Email App", htmlBody: htmlMessage})
<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <table>
  <tr>
    <th>Item Code</th>
    <th>Item Name</th>
    <th>Quantity Needed</th>
  </tr>
  <tr>
    <td><?=BarcodeT ?></td>
    <td><?=ItemName ?></td>
    <td><?=QuantityNeeded ?></td>
  </tr>
    </table>
  </body>
</html>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In your script, how about the following modification?

Modified script:

function email() {
  var Barcode = 0;
  var Name = 1;
  var Added = 2;
  var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Refill Request");
  var data = ws.getRange("A3:D" + ws.getLastRow()).getValues();
  var htmlMessage = "<table><tr><th>Item Code</th><th>Item Name</th><th>Quantity Needed</th></tr>";
  data.forEach(function (row) {
    htmlMessage += `<tr><td>${row[Barcode]}</td><td>${row[Name]}</td><td>${row[Added]}</td></tr>`;
  });
  htmlMessage += "</table>";
  var address = "test@gmail.com";
  MailApp.sendEmail(address, "Refill Request", "Your email doesn't support HTML.", { name: "Email App", htmlBody: htmlMessage });
}
  • In this modification, the HTML table is directly created in Google Apps Script and it is used as the HTML body.
about 4 years ago · Juan Pablo Isaza 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