在Google脚本中超链接文本以发送电子邮件

时间:2018-12-24 19:19:45

标签: google-apps-script

您好,我无法在通过Gmail发送的脚本上使文本超链接。我已经在该网站上测试了其他文章,但是由于将实际电子邮件中的插入,我似乎没有得到正确的代码。

下面是我的脚本(不要介意这里的内容更改)。对于此示例,我想将var消息中的THIS PAGE超链接到www.google.com。您知道如何在Gmail发出的电子邮件中使用它吗?

function sendemail() {
var spreadSheet = SpreadsheetApp.getActiveSheet();
var dataRange = spreadSheet.getDataRange();
// Fetch values for each row in the Range.
var data = dataRange.getValues();
var text = text;
for (var i = 1; i < data.length; i++) {
(function(val) {
  var row = data[i];
  var emailAddress = row[1]; //position of email header — 1
  var firstname = row[0]; // position of name header — 1
  var price = row[2];
  var content = row[25];
  var contenttwo = row[24];
  var html_link = "www.google.com";
  var h = row[22];
  var upcomingDate = Utilities.formatDate(row[3], "GMT+1", "MM/dd/yy");
  //var date = row[3];
  var options = {};
  var subject = "Here's your info";
  var message = "Dear " + firstname + ", " + "\n" + "\n" + content + " $" + price + " xxxxxxxxx" + upcomingDate + "." + "\n" + "\n" + "Please visit this page for more information.";
  //MailApp.sendEmail(content)
  MailApp.sendEmail(emailAddress, subject, message);
  })(i);
 }
 }

1 个答案:

答案 0 :(得分:0)

可能是这样的:

function sendemail() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getActiveSheet();
  var rg=sh.getDataRange();
  var vA=rg.getValues();
  var text='text';
  for (var i=1;i<vA.length;i++) {
    var emailAddress=vA[i][1];//col 2
    var firstname=vA[i][0]; //col 1
    var price=vA[i][2];//col 3
    var content=vA[i][25];//col 24
    var html_link="http://www.google.com";
    var upcomingDate=Utilities.formatDate(new Date(vA[i][3]), "GMT+1", "MM/dd/yy");//if vA[i][3] is a string instead of a date then this may still work
  }
  var subject = "Here's your info";
  var message=Utilities.formatString('Dear %s, <br /><br />%s $%s xxxxxxxxx%s.<br /><br />Please visit <a href="%s">this page</a> for more information.',firstname,content,price,upcomingDate,html_link);
  var message1=Utilities.formatString('Dear %s, \n\n%s $%s xxxxxxxxx%s.\n\nPlease visit %s for more information.',firstname,content,price,upcomingDate,html_link);
  MailApp.sendEmail(emailAddress, subject, message1,{htmlBody:message});

  }
 }