首页 > 解决方案 > 超链接 Google Script 中的文本以发送电子邮件

问题描述

我无法在通过 Gmail 发送的脚本上获取文本超链接。
我已经测试了这个站点上的其他文章,但我似乎没有得到正确的代码,因为它会<a href code>在实际的电子邮件中提取。

下面是我的脚本(不要介意这里的内容更改)。
对于此示例,我想将 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);
    }
}

标签: google-apps-script

解决方案


可能是这样的:

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

  }
 }

推荐阅读