我正在使用Google脚本将电子邮件发送到电子邮件列表。电子邮件列表的一个字段包括为每个收件人定制的超链接。因此,我需要将包含在Google表格中的自定义超链接作为电子邮件的一部分。
function sendEmails() {
// Set the spreadsheet file we are sending from:
var sheetname = SpreadsheetApp.openById('<google sheet url>');
// Set the sheet we are sending from:
var sheet = sheetname.getSheetByName('Send Emails');
// Set the first row of data in the list:
var startRow = 2;
// Set the number of rows of data in the list:
var numRows = 2;
// Fetch the range of cells desired, using formula {first row}, {first column}, {number of rows}, {number of columns}:
var dataRange = sheet.getRange(startRow, 8, numRows, 3);
// Loop through each row in the range set defined above, sending an email based on the values in each row:
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[0]; // First column identified by [0]
var subject = row[1]; // Second column identified by [1]
var html = row[2] + "<a href=" + row[3] + "> click here </a>"; // Third column identified by [2] and fourth by [3]
GmailApp.sendEmail(emailAddress, subject, 'unused but required text',{htmlBody: html});
}
Browser.msgBox(numRows + ' emails were sent successfully.');
}
(在[3]引用的第四列中,每行都有自定义的超链接。)
因此,此代码中的大多数代码都可以正常工作,并且确实生成了链接,但是电子邮件中生成的链接URL为“ http://undefined/”。因此,出于某种原因,它没有从[3]引用的列中获取超链接URL。它取代了“ undefined”