【问题标题】:GmailApp.sendEmail() syntax for multiple options?多个选项的 GmailApp.sendEmail() 语法?
【发布时间】:2015-09-28 00:10:02
【问题描述】:

我想发送带有多个超链接文本、换行符和粗体的电子邮件。除了.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>')})
}

结果如下:

粗体有效,只有 1 个链接没有发生换行。

感谢任何指导!

【问题讨论】:

  • 我最终用 html 编写了整个消息,使用答案中建议的方法:here
  • 还发现这个answer很有用

标签: google-apps-script


【解决方案1】:

您是否尝试过从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});
}

【讨论】:

  • 是的!得到的两个链接都出来了,但是换行符没有出来。当我用'&lt;br/&gt;' 替换'\n' 时,一切正常。如果你想编辑你的第二个代码块,我会检查它作为答案。非常感谢您的帮助。
猜你喜欢
  • 2017-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-30
相关资源
最近更新 更多