简体   繁体   中英

I'm trying to send an email from google spreadsheet, however the message is not copying the hyperlink

I have "to" in column A & "message/body" in column "B". I have a code which sends an email. However in my message I have a word hyperlinked to another sheet, while sending the email, the hyperlink is not considered. Please find the screenshot below. 超链接在 B 列中可见

However when the email is sent, the hyperlink is not visible. Please the image below

电子邮件中不考虑超链接

    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);
  }
} 

UseTemplated 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()
});  

If you have embedded cell links, you can extract them using Advanced Sheets services, as describe here , for example

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);

them use them in templated HTML example I provided.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM