我正在尝试从Google电子表格发送电子邮件,但是该消息未复制超链接

时间:2020-05-24 19:49:42

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

我在A列中有“ to”,在“ B”列中有“ message / body”。我有一个发送电子邮件的代码。但是,在我的消息中,我有一个单词超链接到另一张纸,而在发送电子邮件时,不考虑该超链接。请在下面找到屏幕截图。The hyperlink is visible in column B

但是,发送电子邮件时,超链接不可见。请下图

The hyperlink is not considered in email

    function sendEmails() {    
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2;
  var numRows = 1;
  var dataRange = sheet.getRange(startRow, 1, numRows, 2);
  var data = dataRange.getValues();
  for (var i in data) {
    var row = data[i];
    var emailAddress = row[0]; // First column
    var message = row[1]; // Second column
    var subject = 'Sending emails from a Spreadsheet';
    MailApp.sendEmail(emailAddress, subject, message);
  }
} 

1 个答案:

答案 0 :(得分:2)

使用Templated HTML

var htmlBody = HtmlService.createTemplate('Email with <a href=<?=link?>> Some link </a>');  

htmlBody.link = row[1];

MailApp.sendEmail({
  to: row[0],
  subject: 'Sending emails from a Spreadsheet',
  htmlBody: htmlBody.evaluate().getContent()
});  

如果您具有嵌入式单元格链接,则可以使用Advanced Sheets服务提取它们,例如,如here所述

var values = Sheets.Spreadsheets.get(SpreadsheetApp.getActive().getId(), {ranges: "Sheet1!B1:B10", fields: "sheets/data/rowData/values/hyperlink"})
var links = values.sheets[0].data[0].rowData.map(v => v.values[0].hyperlink);

在我提供的模板化HTML示例中使用它们。