Right Outer Join

28 September 2011

Emailing reports from JasperReports Server

Filed under: JasperReports Server, JasperServer — Tags: , , , , — mdahlman @ 22:12

Emailing reports from JasperReports Server

Standard Answer

Normally JasperReports Server is installed in a corporate environment. You already have an email server, and configuring scheduled reports to get sent out using this email server is simple. The settings are well documented in “JasperReports-Server-Install-Guide.pdf”.

Make-my-life-easy Answer

But what about a simple evaluation situation? You don’t have a corporate email server or you don’t have simple access to it. Shouldn’t it be easy to configure JasperReports Server to use GMail or some other publicly available email server? Yes. It’s possible, and it’s easy. But it’s sometimes hard to track down all of the little details as these email threads can attest:

If you read through all of those threads and read GMail support information, you can indeed find all of the information that you need. But for those that don’t want to wade through the threads, here are the complete details for setting up JasperReports Server to send out email using GMail.

First, edit …/WEB-INF/js.quartz.properties. Use these settings:

report.scheduler.web.deployment.uri=http://localhost/jasperserver-pro
report.scheduler.mail.sender.host=smtp.gmail.com
report.scheduler.mail.sender.username=me@gmail.com
report.scheduler.mail.sender.password=mypassword
report.scheduler.mail.sender.from=me@gmail.com
report.scheduler.mail.sender.protocol=smtp
report.scheduler.mail.sender.port=587

Of course you’ll need to set your own information appropriately. But the GMail server and port need to be as I have indicated.

Second, edit …/WEB-INF/applicationContext-report-scheduling.xml

original version:

<property name="javaMailProperties">
    <props>
        <prop key="mail.smtp.auth">false</prop>
    </props>
</property>

modified version:

<property name="javaMailProperties">
    <props>
        <prop key="mail.smtp.auth">true</prop>  <!--as indicated in JasperReports-Server-Install-Guide.pdf)-->
        <prop key="mail.smtp.starttls.enable">true</prop>  <!--not indicated in JasperReports-Server-Install-Guide.pdf-->
    </props>
</property>

Restart your application, and that’s it. Two quick changes are all that are needed. You should be able to get reports emailed out to your users in under 5 minutes.

Questions

As noted in one of the email threads listed above, the value that you set for “report.scheduler.mail.sender.from” seems to get ignored. I suppose that’s probably a GMail security issue. They don’t allow you to use me@gmail.com to authenticate but then claim that the email came from you@gmail.com. That’s just speculation; maybe someone can comment and confirm. When you are using a corporate email server under your own control it should be possible to set that value to, for example, no-reply@mydomain.com.

Improvements

Perhaps JasperReports Server should be smart enough to figure out that authentication ought to be used based on the fact that you provide a password in js.quartz.properties. I’m not sure if that really would work or not. Ideally we should come up with a mechanism to set javaMailProperties in the properties file. Maybe mail.smtp.starttls.enable ought to be in the documentation. If you want to see any of these changes, then log a bug on the tracker.

Error Reference

If you don’t configure applicationContext-report-scheduling.xml correctly, then you will get an error. I have included the error that I got in case it helps folks with the same error to track down the solution.

2011-09-27 23:18:55,301 ERROR ReportExecutionJob,quartzScheduler_Worker-0:309 - The job error notification was not completed. An error occurred while sending it.
org.springframework.mail.MailSendException; nested exception details (1) are:
Failed message 1:
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. bw6sm18434073qab.16
        at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
        at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
        at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
        at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:403)
        at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:342)
        at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:338)
        at com.jaspersoft.jasperserver.api.engine.scheduling.quartz.ReportExecutionJob.sendMailNotification(ReportExecutionJob.java:1264)
        at com.jaspersoft.jasperserver.api.engine.scheduling.quartz.ReportExecutionJob.executeAndSendReport(ReportExecutionJob.java:446)
        at com.jaspersoft.jasperserver.api.engine.scheduling.quartz.ReportExecutionJob.execute(ReportExecutionJob.java:232)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:195)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)

5 Comments »

  1. hi
    email notiication in jasper server is working now
    thanks alot for your article
    it made my task very easy .
    the mistake was i am giving smtp.webmail.sonata-software.com,which is actually a exchange server address.

    when you are using a exchange server dont use smtp infront of the domain .
    please see the working configuration below

    report.scheduler.mail.sender.host=webmail.sonata-software.com
    report.scheduler.mail.sender.username=my_username
    report.scheduler.mail.sender.password=my_password
    report.scheduler.mail.sender.from=chandrasekhar.k@sonata-software.com
    report.scheduler.mail.sender.protocol=smtp
    report.scheduler.mail.sender.port=25

    report.scheduler.web.deployment.uri=http://localhost:8484/jasperserver

    thanks alot

    Comment by chandrasekhar — 1 February 2012 @ 22:18

    • That’s great to hear. (FYI: I edited your post to remove the username and password, but I left the rest unchanged.)

      Comment by mdahlman — 2 February 2012 @ 10:51

  2. i am getting mail from gmail id to my sonata id using webmail.sonata-software.com as host but not going to gmail id

    Comment by chandrasekhar — 1 February 2012 @ 23:41

    • If JasperReports Server is correctly connecting the the email server to send email… then you have reached the end of knowledge. If email isn’t getting through from your email server to a GMail recipient, that’s probably solvable. But it’s not something that I know about.

      Comment by mdahlman — 2 February 2012 @ 10:54

  3. thanks a lot,
    you made my day. I am able to receive the notification email from Jasperserver

    Comment by Magicien — 5 April 2012 @ 14:23


RSS feed for comments on this post. TrackBack URI

Go on... leave a reply

Blog at WordPress.com.