从电子表格发送HTML电子邮件

时间:2019-12-22 05:59:01

标签: javascript html google-apps-script google-sheets

我正在对教程进行一些改进。该代码从Google电子表格发送电子邮件,并在其中发送邮件并标出主题,并在发送电子邮件时进行标记,我正在尝试使用html编写邮件。

var EMAIL_SENT = 'Correo Enviado';
 //non-duplicate emails with data from the current spreadsheet.



function sendEmails2() {

  var templ = HtmlService.createTemplateFromFile('Correo_HTML').evaluate();

  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2; // First row of data to process
  var numRows = SpreadsheetApp.getActiveSheet().getRange(2,7).getValue(); // Number of rows 

  var dataRange = sheet.getRange(startRow, 1, numRows, 3);

  var data = dataRange.getValues();

  for (var i = 0; i < data.length; ++i) {

    var row = data[i];
    var emailAddress = row[0]; 
    var message = templ.getContent();
    var emailSent = row[3]; 

    if (emailSent !== EMAIL_SENT) { // Prevents sending duplicates
      var subject = row[2];

      MailApp.sendEmail(emailAddress, subject, message);
      sheet.getRange(startRow + i, 4).setValue(EMAIL_SENT);

      // Make sure the cell is updated right away in case the script is interrupted

      SpreadsheetApp.flush();

      }
    }
  }

我正在另一个窗口中编写HTML代码,这非常简单,但我不知道哪里可能出问题

 <!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <h2> Test 2</h2>
    <p>
    Hello World
    </p>
    <p><strong> learning </strong></p>

  </body>
</html>

那么如何在电子邮件中获得HTML代码格式的消息?

0 个答案:

没有答案