1

I am using the final part of this answer to to send an images from Drive as an inlineimage. https://stackoverflow.com/a/41292754/1045794

function sendPicsInline() {
  var picture1 = DriveApp.getFileById('0BxDqyd_bUCmvN1E3N0dQOWgycFE'); //public with link
  var picture2 = DriveApp.getFileById('0BxDqyd_bUCmvTFNjRkRXbXA2Tms'); //public with link
  var inlineImages = {};
  inlineImages[picture1.getId()] = picture1.getBlob();
  inlineImages[picture2.getId()] = picture2.getBlob();
   MailApp.sendEmail({
     to: 'testa@example.com, testb@example.com', 
     subject: "This is a test", 
     body:"Test message",
     htmlBody: 'Test message with pics inline <br>' +
     'first:<br><img src="cid:' + picture1.getId() + '" /><br>' +
     'second:<br><img src="cid:' + picture2.getId() + '" />',
     inlineImages: inlineImages   
  });
}

This is functioning correctly, however it is also listing an attachment on the email - which is particularly frustrating on the android gmail client.

I have tried setting a null attachment option but this does not work. Not that when I use the example from the documentation, but change the URL to any other image, I get an attachment as well as the inlineimage. Using the YouTube logo from the linked documentation, I get only the inlineimage without an attachment.

I cannot understand why - in all instances either from drive or another URL, I am using a PNG file with no other changes.

redditor
  • 4,196
  • 1
  • 19
  • 40

1 Answers1

1

I have images that are stored in Google Drive as DataURI's and I just sent one like this:

function sendEmailWithInlineImage() {
  var file=DriveApp.getFileById('FileId');
  GmailApp.sendEmail('recipient email', 'Inline Images', null, {htmlBody:Utilities.formatString('<h3>Inline Images</h3><img src="%s" />',file.getBlob().getDataAsString())});
}

It was received as an inline image with no attachments.

The first part of the file looks like this: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAMR0lEQVR42u2dbWwUxxnHTYLS0ISURrRRlCDxJkWp+qEKUtK3RHzoh5QPqSLh5mMVJVHVRiBZoY5UVcLxva8NBJOCg5EABRtjDtu8GEPqyqYFXNvY4Ffs89l39l1tn8/2nV8AGwPTnfU+x+Px7N6d70z23Bnpr73bt5ud3z7PMzO7N5OWJlJqpfb29uc9bvcfvF7vCZ/PVyWrRogvv89X3ef1Or29vZ/Scksq

Cooper
  • 59,616
  • 6
  • 23
  • 54