简体   繁体   中英

Hyperlinking email body in HTML

I'm trying to hyperlink text in the email body of this script but can't seem to get it right. Does anyone have any suggestions?

Here is a screenshot of the text I'm trying to hyperlink in the email body message:

截图[1]

Code:

// This constant is written in column D for rows for which an email
// has been sent successfully.
var EMAIL_SENT = 'EMAIL_SENT';

/**
 * Sends non-duplicate emails with data from the current spreadsheet.
 */
function sendEmails2() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2; // First row of data to process
  var numRows = 1000; // Number of rows to process
  // Fetch the range of cells A2:D1000
  var dataRange = sheet.getRange(startRow, 1, numRows, 1000);
  // Fetch values for each row in the Range.
  var data = dataRange.getValues();
  for (var i = 0; i < data.length; ++i) {
    var row = data[i];
    var emailAddress = row[0]; // First column
    var subject = row[1]; // Second column
    var message = row[2]; // Third column
    var emailSent = row[3]; // Fourth column
    if (emailSent !== EMAIL_SENT) { // Prevents sending duplicates
      MailApp.sendEmail(emailAddress, subject, "", {
        htmlBody: message.replace(/\n/g,'<br>')});
      sheet.getRange(startRow + i, 4).setValue(EMAIL_SENT);
      // Make sure the cell is updated right away in case the script is interrupted
      SpreadsheetApp.flush();
    }
  }
}

As people have said in the comment if you want to use an HTML body the way to create an hyperlink is by using the <a> tag .

So for example if you want your mail to look like

Please check out my site

You can write something similar to the following html code:

<p> Please check out my <a href=https://example.com>site</a>

Also in Apps Script maybe you want to create a bigger HTML, which would be too much to create on the execution time, and that would make your code look messy.

You can use HTML files and import them to use in Apps Script, also you have the options to use them as HTML templates

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