Java XLS Report Mail Sender Scheduler Example

Java XLS Report Mail Sender Scheduler Example

In last many tutorial you saw separately. In this example we will create Java application with below functionality:

  • Create multiple XLS sheet with data’s
  • Include creation of XLS through scheduler
  • Send email to one or many people or groups

Tools needed:

  • Any latest version of Eclipse
  • JDK 1.8
  • Quartz jar (Already included in pom.xml)
  • Maven (It comes with eclipse)
  • Java Mails jars¬†(Already included in pom.xml)

Maven project name: ApacheXSSFReportJava

Java XLS Report Mail Sender Scheduler Example

  • Project dependencies: pom.xml:

  • log4j2.xml:

  • JavaHonk.properties:

  • Sample cron and you could also validate is on CronMaker

  • JavaHonk.ftl: FreeMarker template which has been used to show up data summary in Outlook mail page:

  • Spring context file where we load all configuration: common-context.xml

  • mailsettings-context.xml: This file has all configuration which is needed for sending email:

  • scheduler-context.xml: All scheduling related configuration:

  • JavaHonkReportFields: This class has been used to keep all XLS columns names:

  • JavaHonkReportModel.java: This class been used to create dummy data for XLS sheet:

  • JavaHonkExcelReportGenerator.java: This class has all code which is use to generate XLS sheet:

  • MailHelper.java: Helper class has all code to send email:

  • JavaHonkReport.java: Main class which creates XLS sheet put dummy data and send email:

  • JavaHonkMainApp.java: Main class which loads all spring configuration and class JavaHonkReport class to create XLS sheet and send mail. As scheduler has been done through scheduler-context.xml file and it will run every 30 seconds to call “generateReport” operation in JavaHonkReport.java class:

Note: In this tutorial we are using email as well. So if you don’t have real SMTP host yet you could test it with dummy SMTP host. I have used FAKE SMTP to complete the test and validate the CRON time through CronMaker.

  • To run this project: Right click JavaHonkMainApp.java –> Run As –> Java Application (Note: To test this application you will have download FAKESMTP and start it as below:

Java XLS Report Mail Sender Scheduler Example

Java XLS Report Mail Sender Scheduler Example

  • You will in your Fake SMTP email is already published:

Java XLS Report Mail Sender Scheduler Example

Java XLS Report Mail Sender Scheduler Example

  • Double click to email to open it:

Java XLS Report Mail Sender Scheduler Example

Download project: apachexssfreportjava

Leave a Reply

Your email address will not be published. Required fields are marked *