Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Quartz SendMailJob and HTML Format

Posted on 2013-01-28
7
Medium Priority
?
1,147 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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.
Suggested Courses

886 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