GmailApp.sendEmail()语法有多个选项?

时间:2015-08-06 07:28:25

标签: google-apps-script

我想发送带有多个超链接文本,换行符和粗体的电子邮件。除了.sendEmail()文档之外,我发现了question并回答了问题,但我仍然感到困惑。这就是我正在做的事情:

function emailTest() {
var Link1 = "https://sites.google.com/a/****/item-shop" ; 
var Link2 = "https://sites.google.com/a/****/leader-board" ;
var name = "Adam";
var message = "Congratulations " + name.bold() + "!" + '\n' + '\n' + "check out this cool " + Link1 +  '\n' + '\n' +

          "and this cool " + Link2 +  '\n' + '\n' +
          "Keep up the good work!" + '\n' + "Mr. S.";

GmailApp.sendEmail ('fakename@gmail.com', "Congratulations!", message, 
                  {htmlBody: message.replace(Link1, '<a href="https://sites.google.com/a/****/item-shop">Item Shop</a>'),
                  htmlBody: message.replace(Link2, '<a href="https://sites.google.com/a/****/leader-board">LeaderBoard</a>')})
}

结果如下: enter image description here

粗体工作,只有一个链接,没有发生换行。

任何指导表示赞赏!

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用http://协议? 试试这个:

var link = "http://www.google.com";
var message = "Congratulations " + name[i] + "!" + '\n' + '\n' +

          "check out this cool " + link + + '\n' + '\n' +

          "Keep up the good work!" + '\n' + "Mr. S."
GmailApp.sendEmail(fakename@gmail.com, "Congratulations!", message,
{htmlBody: message.replace('link', '<a href="http://www.google.com">Website</a>')})

编辑: 尝试使用电子邮件发送功能分离链接,这也有助于使其更具可读性。试试这个(顺便说一句,我不是那个有谷歌脚本的人,但我很确定这应该有效):

function emailTest() {
  var Link1 = "https://sites.google.com/a/****/item-shop" ; 
  var Link2 = "https://sites.google.com/a/****/leader-board" ;
  var name = "Adam";
  var message = "Congratulations " + name.bold() + "!" + '<br/>' + '<br/>' + "check out this cool " + Link1 +  '<br/>' + '<br/>' +
    "and this cool " + Link2 +  '<br/>' + '<br/>' +
    "Keep up the good work!" + '<br/>' + "Mr. S.";
  message = message.replace(Link1, '<a href="https://sites.google.com/a/****/item-shop">Item Shop</a>');
  message = message.replace(Link2, '<a href="https://sites.google.com/a/****/leader-board">LeaderBoard</a>');

  GmailApp.sendEmail ('fakename@gmail.com', "Congratulations!", message,  {htmlBody: message});
}