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.
2 thoughts to “HTML Mails from XPages – part 2: inline images”
Hi Mark, I’m trying to get your code to work but every time I get the following error message:
Script interpreter error, line=188, col=21: [TypeError] Exception occurred calling method NotesDocument.send() null at [xpHTMLMail].()
//send the e-mail
I fairly new to Notes and XPages (6-7 months). Do you have any ideas what might cause this problem?
Thanks for any help.
It might be because the server isn’t configured correctly and able to send the message. See also this question on StackOverflow. Hope this helps.
Comments are closed.