So I'm trying to add an image below the email that I'm sending via appscript. The script work but no image appears. I've tried googling for answers but the format they use for Mailapp.sendEmail is different.
function sendEmails() {
var templateData = getData("Templates");
var emailSubjectTemplate = templateData[1][0]; //Cell A2
var emailBodyTemplate = templateData[4][0]; //Cell A5
var emailData = getData("Data");
emailData = rowsToObjects(emailData);
emailData.forEach(function (rowObject) {
var subject = renderTemplate(emailSubjectTemplate, rowObject);
var body = renderTemplate(emailBodyTemplate, rowObject);
var inlineImages = DriveApp.getFileById("1PyDU0sOYW_OSMQ1vNpXn9JGf7-I7_dBL").getAs("image/png")
MailApp.sendEmail(rowObject["Email Address"], subject, body, inlineImages);
});
}
I managed to replicate your issue and tried to debug it to show the image inside the email body instead of just as attachment by following the documentation below as my guide.
Replace these lines of code:
var inlineImages = DriveApp.getFileById("1PyDU0sOYW_OSMQ1vNpXn9JGf7-I7_dBL").getAs("image/png")
MailApp.sendEmail(rowObject["Email Address"], subject, body, inlineImages);
To this:
var image = DriveApp.getFileById('1PyDU0sOYW_OSMQ1vNpXn9JGf7-I7_dBL').getBlob();
MailApp.sendEmail({
to: rowObject["Email Address"],
subject: subject,
htmlBody: body + "<img src=\"cid:bodyImage\">",
inlineImages: {bodyImage: image}
});
Sample email output:
Reference: sendEmail(message)