Emailing reports from JasperReports Server
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”.
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:
- What are the setting values in order to use Gmail
- jasperserver 3.7 mail schedule using gmail smtp
- From variable isn’t working?
- how can send reports by emails ??
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 email@example.com report.scheduler.mail.sender.password=mypassword firstname.lastname@example.org 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
<property name="javaMailProperties"> <props> <prop key="mail.smtp.auth">false</prop> </props> </property>
<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.
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 email@example.com to authenticate but then claim that the email came from firstname.lastname@example.org. 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, email@example.com.
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.
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)