Wednesday, May 26, 2010

Pentaho reports by email - with steroids




Most people don't know this but there's an hidden gem inside Pentaho 3.5 (and the soon to be released 3.6);

The ability to send a report by email ...


Nothing new so far?

... with all images and resources inline


So no more of being forced to send pdf attachments in boring text or html emails, or the need to have your pentaho server accessible in the www. Pretty cool, hein?


Did you just said you like the pdf attachments?


You can still send your pdf attachments with the html email!



And I'm not done yet! Want to impress your friends of the other company by receiving yesterday's sales report on your smartphone while having breakfast?


Just render a text version of that report



and it'll automagically generate a mime/alternate email message and your email client will chose the best format to display the information to you



You didn't know this was possible? It's all in there. More than one and a half year's ago we developed a bunch of patches to allow this. And why? Because one of our customers wanted this feature. <shamelessplug> And that's what we do, develop cool stuff for our customers</shamelessplug>


We added:


* A new repository implementation was built to allow the generation of a mime-message directly from the jfreereport engine (with Thomas Morgner's help, of course)

* A patch to the reporting plugin to add a new supported output-type 'email'

* Support to the text output in the reporting plugin

* A SimpleEmailComponent POJO that sends the emails


The existing action to send emails is very limiting, so we had to develop a new one. Pentaho guys allowed this to be commited along with the reporting plugin. We all agree that the BI suite need a full-featured email component so this POJO will eventually be moved out of the reporting plugin. But until that happens - hey, let's use it!


nuff said; Want to see this working? We stored on webdetails site an archive of all the necessary files. Unzip it to your pentaho solution folder of choice, see how it works and feel free to play with it!


Have fun!

19 comments:

  1. Cool stuff Pedro. Just a quickie to say that the link to the necessary files is broken.

    Abraços,

    ReplyDelete
  2. Opps! Fixed, thanks for noticing!

    ReplyDelete
  3. The Send Reportby Email Xaction did not execute. Already modified the report with my settings database, it runs successfully. But the xaction failure.
    Is necessary some change in xaction?

    ReplyDelete
  4. Should work out of the box provided you have the email sending capabilities of your pentaho installation working properly

    ReplyDelete
  5. Ok, the problem is on my network that can't access the gmail smtp.

    You said about repoting plugin, but nothing about sending email using the plugin.
    Would it be possible not use xaction and customize the report plugin? I downloaded the source platform and plugin to add menu item(right button) to send the email report. The changes would be in ReportContentGenerator class.

    Some suggestion?

    ReplyDelete
  6. that would be an interresting add-on for pentaho, Thiago. Are you sure, none already exists?

    ReplyDelete
  7. This comment has been removed by a blog administrator.

    ReplyDelete
  8. Great work, but I can't figure out where to put the report parameters. I suspect in the PojoComponant inputs somewhere.

    ReplyDelete
  9. Hello there

    It's the standard and boring xaction rules

    ReplyDelete
  10. Oh, OK great. I guess my understanding of xactions is tenuous as best. I'll look into that.

    A second question: Ii appears to me that Gmail and at least 1 other mail reader is not applying the css rules for the html email. In the email I see the reference in the HTML header:

    link type="text/css" rel="stylesheet" href="cid:style.css"

    and I see the css attachment:

    ------=_Part_34_12012951.1280500408046
    Content-Type: text/css; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    Content-ID: style.css

    But the two are not put together when the email is rendered, so I get HTML with the default style. Is this an email reader issue, or a setup issue, or even a Pentaho component issue?

    ReplyDelete
  11. Complain to google. They mess a lot with the html and therefore there's not much one can do about it. If you try thunderbird / any other client should work as expected.


    There's an option you can set in PRD to tell him not to use external styles but write the style in the html component. Bigger file, but more compatibility

    ReplyDelete
  12. yea, about a minute after I commented I saw about Gmail and css (I was thrown off by the rendering on my my phone imap client). I changed the report so it works fine either way.

    Many thanks

    ReplyDelete
  13. Hi!
    I have a problem with the execute,
    Error: Could not load bean class - java.lang.ClassNotFoundException: org.pentaho.reporting.platform.plugin.SimpleEmailComponent (org.pentaho.platform.engine.services.solution.PojoComponent)

    I work with Pentaho 3.5.0.stable.
    Do I must install something?

    Thanks very much

    ReplyDelete
  14. This really is a hidden gem, thanks! Have you found a work-around for Outlook 07 and 2010? Most of the css styles are ignored because they're now using Word to render :(

    http://blogs.sitepoint.com/microsoft-breaks-html-email-rendering-in-outlook/

    ReplyDelete
  15. Can i send to multiple emails?

    ReplyDelete
  16. Sure - just tweak the xaction to loop on whatever you want

    ReplyDelete
  17. Hey Pedro!

    First of all, you are a life saver. I had been trying to figure this out for so long, and your xaction template worked like a dream. You are the best!

    I only have one problem - all images / charts in the report end up as blank frames in the html body text, and are attached as files in the email instead of imbedding them inline. Is this a problem specific to gmail, or is there some configuration that I'm missing in the xaction or the .prpt? (along the same lines as turning on in-line styles for html output?)

    ReplyDelete
  18. Great work Pedro! I really like the addition and it was easy to get going quickly. Can't wait to get it into production.

    ReplyDelete