I’ve updated the HTML mail SSJS library I wrote about yesterday and have added inline images support. This can come in handy when you want to create HTML newsletters.
Marking an image as “inline” can be done by adding an extra parameter to the addDocAttachment() / addFileAttachment() methods:
mail.addDocAttachment( "5203C670815BC8C4C12579270029C543", "header.gif", true );
The addDocAttachment/ addFileAttachment methods now return the Content ID of the image in the message. That ID can then be used to reference the image in the contents:
var headerImgId = mail.addDocAttachment("5203C670815BC8C4C12579270029C543", "header.gif", true); mail.addHTML("<table><tbody><tr><td>"); mail.addHTML("<img src="" + headerImgId + "" />;"); mail.addHTML("</td></tr></tbody></table>;");
If I send an email to my GMail account using my library containing only inline images, the email is considered not to have attachments (no paperclip icon in the messages list). If you have also chosen that images from that specific sender can always be shown, they also don’t show up at the bottom of the message (in the section containing all attachments).
To test if everything worked correctly I downloaded a sample HTML email template from FreeMailTemplates.com, uploaded all images to a sample database and created a mail message. In the downloaded index.html file I removed all line-breaks (rn) and tabs (t) using Notepad++. I then added the HTML (starting at the first table tag) to the message using the addHTML() method. I replaced all referenced images as described above. The message I received in GMail looked exactly how it was supposed to look:
I’ve tested the inline image functionality in GMail and Notes 8.5.3. You can download the library here.