如何将HTML电子邮件代码模板添加到javascript以使用googlesheet发送个性化邮件

时间:2018-05-25 12:35:53

标签: html google-apps-script gmail

你好SOF的朋友我是新来的,我有一个问题,我相信可以在这里排序。我正在使用谷歌工作表发送电子邮件。我有一个工作代码,使用谷歌表向个人发送个性化的电子邮件,它工作正常。问题是我想在邮件中添加一个html电子邮件模板,而不仅仅是计划文本。下面是我的设置图片,目前工作正常但不知道如何将我的html电子邮件模板代码添加到邮件消息正文中。我将消息正文标记为黄色,我想用我的html电子邮件代码模板替换该消息。我还会为您提供样本代码进行复制和试用,您只需要创建谷歌电子表格并将电子邮件字段放在最后以测试执行。

VIEW SHEET AND SCRIPT FILE HERE

VIEW HTML EMAIL CODE TEMPLATE HERE

function sendEmails() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2; // Start at second row because the first row contains the data labels
  var numRows = 3; // Put in here the number of rows you want to process

  // Fetch the range of cells A2:B4
  // Column A = Email Address, Column B = First Name
  var dataRange = sheet.getRange(startRow, 1, numRows, 2)
  
  // Fetch values for each row in the Range.
  var data = dataRange.getValues();
  for (i in data) {
   var row = data[i];
   var emailAddress = row[0]; // First column of selected data
   var message = "Hey " + row[1] + ",\n how are you doing today?"; // Assemble the body text
   var subject = "Sending emails from a Spreadsheet";
   MailApp.sendEmail(emailAddress, subject, message);
  }
}

0 个答案:

没有答案