在 Google Apps 脚本上向内联图像添加超链接

Adding a hyperlink to an inline image on Google Appscript

我有以下代码,可以将内联图像添加到从 google sheet 发送的电子邮件中。我正在努力为内联图像添加超链接。任何关于如何实现这一目标的指导将不胜感激!

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

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

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

在这种情况下,将超链接添加到 <img src=\"cid:sampleImage\"> 怎么样?

修改后的脚本:

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

function myFunction() {
  var url = "https://cdn.sstatic.net/Sites/Whosebug/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 = "";  // 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}
  });
}
  • 当您 运行 脚本时,您可以看到一封电子邮件,其中包含带超链接的内联图像。

参考:

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