Inserting a Picture in Google Sheets Email Script

Hey everyone,

I'm working on a Google Sheets script to send emails, but I'm stuck on adding a picture to the message. I've tried using inline images, but it's not working with the MailApp option I'm using.

I want to put this picture right after the names at the end of the email, before the website link:

[Picture of NSF Northeast Big Data Industry Logo]

Here's a snippet of my code:

```javascript
var msgHtml = "Dear " + Firstname + "," + "</p>"
  // ... other email content ...
  +"<p>"+"René Bastón"+"<br/>"+ 
  "Kathy McKeown"+ "</p>" +
  // I want to add the image here
  +"</p>"+ "<p>"+"ourwebsite.org" + "</p>";

Any ideas on how to add the image? Thanks for your help!

I encountered a similar issue with embedding images in email scripts before. Converting the image to a base64 string and then embedding it directly within an tag in your HTML solved the problem for me. This method avoids the complications of inline images with MailApp and eliminates extra permissions. I replaced any list formatting with a clear explanation in paragraphs. Just make sure the size of your base64 string stays within email limits, and your approach should work reliably.

I’ve successfully tackled this challenge in my projects. Instead of using MailApp, I switched to GmailApp for more flexibility with images. Here’s what worked for me:

First, upload your image to Google Drive. Then, use DriveApp to fetch the file and create a blob. Next, create an inline image using GmailApp.createDraft() method. Finally, insert the image into your HTML using its content ID.

Here’s a rough outline:

var file = DriveApp.getFileById(‘your_image_id’);
var blob = file.getBlob();
var draft = GmailApp.createDraft(‘’, ‘’, ‘’);
var inline = draft.attachments[0];
var imgTag = ‘’;

Insert imgTag where you want the image in your HTML. Then use GmailApp.sendEmail() with the htmlBody option. This approach has been reliable in my experience, though it does require additional setup.

hey there, i’ve dealt with this before. you can try using the DriveApp to get the image file and then use its ID to create an inline image. something like:

var file = DriveApp.getFileById(‘your_image_file_id’);
var imageBlob = file.getBlob();
var inlineImage = MailApp.addInlineImage(imageBlob);

then just add inlineImage.getContentId() to ur html. hope this helps!