How do i send a google slide as an attachment in my email using google-appscripts?

Viewed 219

I'm trying to send a google slide as an attachment/image in my automated email using google appscripts but i can only send images. I change the slide info everyday so I need it to display the new info hence i dont want to keep changing the image everyday.

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

This code send a text followed by 2 images side by side. I need it to send a text followed by 2 google slide side by side that will automatically update everytime i change anything on the google slide.

1 Answers

Getting Images of Slide Presentations

The first function will store all of your slides as images in a local folder of your choice. It also copies Filename, FileId, height, width, and URL to the active page for later reference. You may wish to modify it in order to just select one image. You will also need to enable to Advanced Slides API in order to use this function because it is at the actual element that is capable of getting access to an image of a slide.

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

The next function is just a simple example of sending an image file as an attachment to an email.

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 This reference is very helpful in figuring out the syntax for API thumbnail options.

Thumbnail Size Options

The rest is just standard DriveApp code.

This is what the Spreadsheet Info looks like:

enter image description here

Related