Jump to content

JasperServer / Microsoft Exchange HTML Rendering Problem

Go to solution Solved by luigiw,

Recommended Posts

Hello everyone,

First time posting.

I'm having a problem emailing HTML reports.  I'm using Microsoft Outlook 2011 on a Mid 2012 Macbook Pro running Mavericks (10.9.5) to view my e-mail.  My e-mail account connects to Microsoft Exchange.  When I receive an e-mail sent by JasperServer, the e-mail arrives with multple attachment named ATT0000*.bin (with * being a number assigned to the attachment) and the images do not display.  Instead the name of the bin file is displayed where the image should be.

However, using the same client, if I connect to my e-mail account via IMAP, the image renders just fine.  It also renders fine in web based e-mail clients, on my phone, and in the JasperServer UI.

At first I thought it was this: https://support.microsoft.com/en-us/kb/969854

However, the images are being place at the end of the e-mail message as they should be.

Has anyone else expereinced this problem and, if so, what did you do to fix it?

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Outlook does a poor job in rendering HTML emails, it normally will use word as the HTML viewer and as we know MS Words is not the best HTML rendering engine, also if I'm not mistaken when connected to exchange it interprents the emails as rich test (RTF) not HTML that is why you see the diference between exchange and IMAP.

Check this post about how Outlook (poorly) renders HTML in the different versions of the client https://litmus.com/blog/a-guide-to-rendering-differences-in-microsoft-outlook-clients

Link to comment
Share on other sites

That makes sense HTML emails sent from other sources are built around the limitations of the HTML rendering of common email clients like outlook. Here you are receiving a full HTML report that uses very heavily CSS, positioning, images, javascript, etc.


As you say in your comment the problems has to do with Exchange, since outlook via IMAP can render it ok, as well as other email clients.


If you have to use exchange your best bet is to schedule the report as PDF and attach it.

Link to comment
Share on other sites

  • Solution

When JasperReports renders a report in HTML, the images have no file extension.

When an image is attached to an e-mail with no extension, Microsoft Exchange compresses it into a bin file and the image will not render in the e-mail body.  I don’t know if this is how all instances of Microsoft Exchange operate.

I had to find a way to force an extension to be appended to the image file name.

I downloaded the source for jasperreports-6.0.3 and edited src/net/sf/jasperreports/engine/export/AbstractHtmlExporter.java.

I changed

return IMAGE_NAME_PREFIX + printElementIndex.toString();


return IMAGE_NAME_PREFIX + printElementIndex.toString() + ".png";

and then compiled a new jar (jasperreports-6.0.3.jar) and put it in jasperreports-server-cp-6.0.1/apache-tomcat/webapps/jasperserver/WEB-INF/lib/ (replacing the old jasper reports jar) and restarted the server.

That solved the problem with Microsoft Exchange…but it broke the report viewer in jasper server UI.

Fortunately, by default the e-mailer always uses HtmlExporter.java (located in src/net/sf/jasperreports/engine/export/) and there are two other renderers that can be selected for rendering html in the report viewer….but I have found that HtmlExporter.java works the best.

I overwrote the contents of JRHtmlExporter.java (located in src/net/sf/jasperreports/engine/export/s) with the contents HtmlExporter.java, changed all occurrences of “HtmlExporter” to “JRHtmlExporter” in the new JRHtmlExporter.java and changed the line

String imageName = getImageName(imageIndex);


String imageName = getImageName(imageIndex).replaceAll(".png","”);

and the compiled a new jar (jasperreports-6.0.3.jar) and put it in jasperreports-server-cp-6.0.1/apache-tomcat/webapps/jasperserver/WEB-INF/lib/ (replacing the old jasper reports jar).

Then, lastly, in jasperreports-server-cp-6.0.1/apache-tomcat/webapps/jasperserver/WEB-INF/classes/jasperreports.properties I selected


as my renderer (which invokes the new JRHtmlExporter), and restarted the server.

Essentially, one renderer which implements my extension change is being used by the e-mailer and one renderer which implements the change but then changes it back to the way it was is being used by the report viewer.

It worked..but it is a very complicated workaround.

Two years ago there was a request to include the file extension in images.  To my knowledge, it hasn’t been implemented

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...