Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Quartz SendMailJob and HTML Format

Posted on 2013-01-28
7
Medium Priority
?
1,127 Views
Last Modified: 2013-02-05
Hi All,

I am using the Quartz SendMailJob to send a report by email. My requirement is to send the Report in HTML format. However, MS Outlook is not recognizing the format and displaying HTML text as is.

My method is as below:

      private void sendEmail(JobExecutionContext arg0, String jobMessage) {
            if(arg0.getMergedJobDataMap().containsKey("recipient")){
                  //send an e-mail to the recipient
                  try {
                        arg0.getMergedJobDataMap().put("message", jobMessage);
                        arg0.getMergedJobDataMap().put("contentType", "text/html");
                        
                        SendMailJob mailJob = new SendMailJob();
                        mailJob.execute(arg0);
                        logger.info(jobMessage);
                  } catch (Exception e) {
                        e.printStackTrace();
                        StringBuilder message = new StringBuilder();
                        message.append("Could not send email to ");
                        message.append(arg0.getMergedJobDataMap().getString("recipient"));
                        logger.info(message);
                  }
            }
      }
0
Comment
Question by:somaghoshCU
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 38827626
Please post an example (obfuscated if necessary) of a mail body
0
 

Author Comment

by:somaghoshCU
ID: 38827701
Here it is:

      StringBuilder html = new StringBuilder();
            html.append("<html>");
            html.append("<head><h1>Test Report</h1></head>");
            html.append("<body>");
            html.append("<table cellpadding='10'>");
            html.append("<th align='left'>Reference ID</th><th align='left'>Origination Date</th><th align='left'>Previous Status</th>");
            html.append("<tr>");
            html.append("This is the Report Body");
            html.append("</tr>");
            html.append("</table>");
            html.append("</body>");
            html.append("</html>");
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 200 total points
ID: 38828010
That's certainly ok if the headers have been set correctly. I'm not convinced they have but unfortunately the api docs that i'm able to see are decidedly thin when it comes to comment/explanations:
http://quartz-scheduler.org/api/2.0.0/org/quartz/jobs/ee/mail/SendMailJob.html
If you know of any better ones, let me know.
Perhaps you ought to be using http://quartz-scheduler.org/api/2.0.0/org/quartz/jobs/ee/mail/SendMailJob.html#PROP_CONTENT_TYPE but i'm not sure. If you can find a link to the source, post that too please.

Otherwise, someone who's actually used this api might come along...
0
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
LVL 27

Expert Comment

by:mrcoffee365
ID: 38828177
You're not appending the html as a mime attachment.  That will almost certainly fix the problem.
0
 

Author Comment

by:somaghoshCU
ID: 38828298
mrcoffee365,

Would you give an example as the current documentation does not show one. It will be really helpful!
0
 
LVL 27

Accepted Solution

by:
mrcoffee365 earned 800 total points
ID: 38829064
The current document has 2 calls relating to the mime message attachment.  This person shows an example (with Velocity and Spring, but you can ignore those parts):
http://shahmukesh.wordpress.com/2010/12/02/spring-integration-with-quartz-for-sending-bulk-e-mails/

He doesn't mention it, but you should try setting the content-type for your email to "text/html" to see if that helps with your current implementation.

To see the api, here:
http://quartz-scheduler.org/api/2.0.0/org/quartz/jobs/ee/mail/SendMailJob.html

We don't use Quartz to send email, but apparently it's a fairly simple-minded interface.  They expect you to write your own implementation of it if you have additional needs.  See this discussion here:
http://stackoverflow.com/questions/12517219/example-using-quartz-sendmailjob
0
 

Author Comment

by:somaghoshCU
ID: 38855863
I am posting my implementation for reference. Thank you mrcoffeee365 and CEHJ!

Extend the SendMailJob and implement the following:

protected void setMimeMessageContent(MimeMessage mimeMessage, MailInfo mailInfo) throws MessagingException {
            final MimeBodyPart textPart = new MimeBodyPart();
              textPart.setText("This is the text");

            // HTML version
             final MimeBodyPart htmlPart = new MimeBodyPart();
            htmlPart.setContent("<html><body>...</body></html>", "text/html");
            htmlPart.setFileName("test.html");

            // Create the Multipart.  Add BodyParts to it.
            final Multipart mp = new MimeMultipart();
            mp.addBodyPart(textPart);
            mp.addBodyPart(htmlPart);

            // Set Multipart as the message's content
            mimeMessage.setContent(mp);
}
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn different types of Android Layout and some basics of an Android App.
This video teaches viewers about errors in exception handling.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question