I am trying to add an inline image to an email, which is working, but it's adding the image as attachment instead. Am I doing something wrong here?
function sendEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet1=ss.getSheetByName('Data');
var n=sheet1.getLastRow();
for (var i = 2; i < n+1 ; i++ ) {
var emailAddress = sheet1.getRange(i,1).getValue();
var html = HtmlService.createTemplateFromFile('Document.html');
var img = DriveApp.getFileById('1NgViZuezxzqugtGFp8vPXe234s00ZNwg').getBlob();
var aliases = GmailApp.getAliases();
Logger.log(aliases);
GmailApp.sendEmail(emailAddress, 'Annual Review', html,{
htmlBody: html.evaluate().getContent(),
name: "Administrators",
from: aliases[0],
inlineImages: {image: img}
});
}
}
Answer:
The HTML portion of the email needs to have the img tags for the files.
Code Example: