Estoy escribiendo una función de correo electrónico que se supone que debe enviar un correo electrónico de TODOS los datos de rango en la hoja de cálculo después de hacer clic en un botón, el problema es que no puedo recibir un correo electrónico con todos los datos, en cambio, cada correo electrónico se envía individualmente a través del ciclo. ¿Hay alguna manera de que pueda enviar todos los datos como datos HTML en un solo correo electrónico? Cuando coloco var htmlMessage=emailTemp.evaluate().getContent(); fuera del bucle que activa BarcodeT no está definido.
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>En su guión, ¿qué tal la siguiente modificación?
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 }); }