1

我有下面的代码,它将内联图像添加到从谷歌表格发送的电子邮件中。我正在为内联图像添加超链接。任何有关如何实现这一目标的指导将不胜感激!

    var pwcURL2 = DriveApp.getFileById("1C56M6DeZCm9IK5K26Z_ZYNLMb8rdqB4a").getBlob();

    var pwcblob = UrlFetchApp
                            .fetch(pwcURL)
                            .getBlob()
                            .setName(pwcblob)

//Some more lines of code in the middle which I have skipped as they are not relevant to the question being asked here

    bodypwc = "<img src='cid:pwc' style='width:24px; height:16px;'/>" + bodypwc;
    MailApp.sendEmail({ 
      to: currentEmail,
      subject: subjectLine, 
      body: messageBody,
      attachments: [liabilityWaiver1,liabilityWaiver2],
      htmlBody: messageBody+"<BR/><BR/>"+"<img src=\"cid:sampleImage\">",
      inlineImages: {sampleImage: pwcURL2}
    });

4

1 回答 1

3
  • 您想要将超链接添加到 Gmail 的内嵌图像。
  • 您想使用 Google Apps 脚本实现此目的。

如果我的理解是正确的,这个答案怎么样?请认为这只是几个可能的答案之一。

在这种情况下,如何添加超链接<img src=\"cid:sampleImage\">

修改后的脚本:

当你的脚本被修改后,它变成如下。

function myFunction() {
  var url = "https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-logo.png";  // Sample image
  var image = UrlFetchApp.fetch(url).getBlob();
  var currentEmail = "###";  // Please set the email address.
  var subjectLine = "sample subject";  // Please set the subject.
  var messageBody = "sample message body";  // Please set the email body.
  var urlForInlineImage = "https://stackoverflow.com/q/60689970/7108653";  // Please set the URL you want to add to the inline image. Here, the URL of this question is used as a sample URL.

  MailApp.sendEmail({ 
    to: currentEmail,
    subject: subjectLine,
    body: messageBody,
  //    attachments: [liabilityWaiver1,liabilityWaiver2],  // Here, as a sample case, no attachment files are used.
    htmlBody: messageBody+"<BR/><BR/>"+"<a href=\"" + urlForInlineImage + "\"><img src=\"cid:sampleImage\"></a>",
    inlineImages: {sampleImage: image}
  });
}
  • 运行脚本时,您可以看到一封电子邮件,其中包含带有超链接的内联图像。

参考:

如果我误解了您的问题并且这不是您想要的方向,我深表歉意。

于 2020-03-15T06:38:45.520 回答