Send email from a spreadsheet with whole formattin

2019-07-23 13:38发布

Hi am trying to send a table to a mail from a google spreadsheet but all am getting is "[object Object]" in mail, here is my script.

function sendEmail() {
  var s = SpreadsheetApp.getActive().getSheetByName('Summary');
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var range = ss.getActiveSheet().getDataRange();
  var range = s.getRange('A1:D8');
  var to = "srinath@example.com";
  var body = '';
  var htmlTable = SheetConverter.convertRange2html(range);
var body = "Here is the table:<br/><br/>"
     + htmlTable
     + "<br/><br/>The end."

  MailApp.sendEmail(to, 'Subject', {htmlBody: body});
};

I want t send the whole table and formatting in to tha mail body I got Sheetconverter Libraries from this link Use MailApp to send formatted data from spreadsheet in htmlBody Please help me

1条回答
forever°为你锁心
2楼-- · 2019-07-23 14:05

When sending HTML in the body of an email, you need to include options specifically stating that there is an HTML body.

MailApp.sendEmail(email, 'Subject', body, {htmlBody: body})

The {htmlBody: body} bit is what you where missing.

Modified code:

function sendEmail() {
  var s = SpreadsheetApp.getActive().getSheetByName('Summary');
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var range = ss.getActiveSheet().getDataRange();
  var range = s.getRange('A1:D8');
  var to = "srinath@example.com";
  var body = '';
  var htmlTable = SheetConverter.convertRange2html(range);
var body = "Here is the table:<br/><br/>"
     + htmlTable
     + "<br/><br/>The end."

  MailApp.sendEmail(to, 'Subject', body, {htmlBody: body});
};
查看更多
登录 后发表回答