How to include inline images on "send as email" for Blog Posts

Discussion created by mark.cablayan on Oct 15, 2012
Latest reply on Mar 11, 2013 by pawans

We needed to implement a way to include inline images on the "send as email" functionality and I thought it might be helpful for anyone trying to do the same.


I extended the class and added the following code block to the sendContentNotification(String recipientName, String recipientEmail) method.


if(jiveObject.getObjectType() == JiveConstants.BLOGPOST) {
            BlogPost bg = (BlogPost)jiveObject;
            JiveIterator<Image> itr = bg.getImages();
            while(itr.hasNext()) {
                Image i =;
                String imageName = i.getName().replace(" ","");                
                try {
                    message.addAttachment(new InputStreamDataSource(imageName,new MimetypesFileTypeMap().getContentType(attachmentNameFrom(i)),i.getData()));
                    String regex = "<a href=\".*" + i.getName().replace(" ", "\\+").replace(".","\\.") + ".*?<\\/a>";
                    String imgTag = "<img src=\"" + imageName +"\">";
                    objectHtmlBody = objectHtmlBody.replaceAll(regex, imgTag);
                } catch (IOException e) {


This adds the images to the email as attachments and adds "img" references in place of the original hrefs.

The admin console restricts our image sizes, so we decided not to include any size restrictions in the actual code, however, in can be added rather easily.