javascript - 如何使用 google-appscripts 在我的电子邮件中将 google 幻灯片作为附件发送?

标签 javascript html google-apps-script

我正在尝试使用 google appscripts 在我的自动电子邮件中将 google 幻灯片作为附件/图像发送,但我只能发送图像。我每天都更改幻灯片信息,所以我需要它来显示新信息,因此我不想每天都更改图像。

// This code fetches the Google and YouTube logos, inlines them in an email
// and sends the email
function inlineImage() {
var googleLogoUrl = "https://i.imgur.com/CWmA6Jv.png";
var youtubeLogoUrl =
    "https://i.imgur.com/CWmA6Jv.png";
var googleLogoBlob = UrlFetchApp
                     .fetch(googleLogoUrl)
                     .getBlob()
                     .setName("Scratches Alert");
var youtubeLogoBlob = UrlFetchApp
                      .fetch(youtubeLogoUrl)
                      .getBlob()
                      .setName("Scratches Dashboard");
MailApp.sendEmail({
to: "test@testmail.com",
subject: "Scratches Awareness Program",
htmlBody: "<p>This is to inform about the progress of Scratch Awareness 
Programme.<p> Engineers, supervisors & shift leaders are expected to 
display and brief thier team on the latest update based on visual comm. 
Everyone's involvement is highly appreciated. Please click on the given 
link to access Scratches Alert and Dashboard: 
https://www.youtube.com/watch?v=dQw4w9WgXcQ</p></p><p><img 
src='cid:googleLogo' width='500' height='333'><img src='cid:youtubeLogo' 
width='500' height='333'></p>",
inlineImages:
  {
    googleLogo: googleLogoBlob,
    youtubeLogo: youtubeLogoBlob
    }
  });
 }

此代码发送一条文本,然后并排发送 2 张图片。我需要它来发送一条文本,然后并排发送 2 张谷歌幻灯片,每次我更改谷歌幻灯片上的任何内容时,它都会自动更新。

最佳答案

获取幻灯片演示文稿的图像

第一个函数会将所有幻灯片作为图像存储在您选择的本地文件夹中。它还将文件名、文件 ID、高度、宽度和 URL 复制到事件页面以供以后引用。您可能希望修改它以便只选择一个图像。您还需要启用 Advanced Slides API 才能使用此功能,因为它位于能够访问幻灯片图像的实际元素中。

function getImagesOfSlides() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getActiveSheet();
  sh.clearContents();
  sh.appendRow(['FileName','FileId','Height','Width','URL']);
  var presentationId="Presentation Id";
  var fldr=DriveApp.getFolderById("File Folder Id");
  var sp=SlidesApp.openById(presentationId);
  var slds=sp.getSlides();
  var n=1;
  for(var i=0;i<slds.length;i++) {
    var pageObjectId=slds[i].getPageElements()[0].getParentPage().getObjectId();
    if(pageObjectId) { 
      var respObj=Slides.Presentations.Pages.getThumbnail(presentationId, pageObjectId, {"thumbnailProperties.mimeType":"PNG","thumbnailProperties.thumbnailSize":"MEDIUM"});
      var imgBlob=UrlFetchApp.fetch(respObj.contentUrl).getBlob();
      var file=fldr.createFile(imgBlob).setName('Slide'+ n++ + '.png');
      sh.appendRow([file.getName(),file.getId(),respObj.height,respObj.width,respObj.contentUrl]);
    }
  }
}

下一个函数只是将图像文件作为电子邮件附件发送的简单示例。

function sendSlide() {
  var fileId="File Id";
  var file=DriveApp.getFileById(fileId);
  GmailApp.sendEmail('recipient email', 'Sending An Image', 'This is a test file', {attachments:[file]});
}

API Reference该引用资料对于了解 API 缩略图选项的语法非常有帮助。

Thumbnail Size Options

其余只是标准的 DriveApp 代码。

这是电子表格信息的样子:

enter image description here

关于javascript - 如何使用 google-appscripts 在我的电子邮件中将 google 幻灯片作为附件发送?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58533111/

相关文章:

javascript - 无法读取未定义的属性“映射”

google-apps-script - 如何从 google apps 脚本中的 urlfetch 获取 Google 搜索结果

google-apps-script - Google Script 中的面向对象前端是否有解决方法

javascript - 使用 JavaScript 在当前日期上添加 5 天

javascript - 如何使用可变字符串访问对象?

javascript - 单击 MVC 应用程序中的标签时如何选中所有复选框?

javascript - 当分隔符为 ' '(空格)时,Google Apps 脚本运行时 Chrome V8 会导致 Utilities.parseCsv(csv, delimiter) 出错

javascript - 我如何限制 angularjs 中的 $http 请求?

javascript - Flash - 将音频数据 ByteArray 传递给 javascript

javascript - 在 MS Word 文件中嵌入 HTML