Send HTML Tables
function sendMailWithTable() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sample_Data");
var bodyEmail = "Hi All, <br/> Please find the latest data given below. <br/> "
var totalRows = sheet.getLastRow();
var totalCols = sheet.getLastColumn();
var table = "<html><body><br><table border=1>"
var colVal = "";
for (var rowNo = 1; rowNo <= totalRows; rowNo ++) {
table = table + "<tr>"
for (var colNo = 1; colNo <=totalCols; colNo++) {
colVal = sheet.getRange(rowNo ,colNo).getDisplayValue();
if(rowNo==1){
table = table + "<th>" + colVal + "</th>";
}
else{
table = table + "<td>" + colVal + "</td>";
}
}
table = table + "</tr>"
}
bodyEmail=bodyEmail + table
GmailApp.sendEmail("aaa@abcdpqrs.com","Latest Data","",{htmlBody:bodyEmail});
}