XML : How to Keep the HTML formatted data as a body of java mail using java mail API?

I need to mail the xml validation Reports as a HTML content mail. How to keep the below detailed information(derived from a parent class)as a HTML body using java mail api. //Exact Requirement: TITLE : CAR Validation Report //Background color : orange //Font color : Black 1.Total No of Errors : 12 2.Total No of Warnings : 150

CAR Validation Successful.

My java code for mail:

  MimeMessage message = new       MimeMessage(session);                                                     m_toterr=validatexml.Total_err;                  message.setFrom(new InternetAddress(from));                     message.addRecipient(Message.RecipientType.TO, new   InternetAddress(to1));                  //message.addRecipient(Message.RecipientType.CC, new    InternetAddress(to2));                  //message.addRecipient(Message.RecipientType.BCC, new   InternetAddress(to3));                  //message.addRecipient(Message.RecipientType.BCC, new   InternetAddress(to4));                  message.setSubject("RE : CAR Validation Report of :   "+dateFormat.format(cal.getTime()));                   message.addHeaderLine("line");                  MimeHeader header1=new MimeHeader("Content-  Type","test/html");                  MimeBodyPart line0 =new MimeBodyPart();                  MimeBodyPart line1 = new MimeBodyPart();                  MimeBodyPart line2 = new MimeBodyPart();                  MimeBodyPart line3 = new MimeBodyPart();                  MimeBodyPart line4 = new MimeBodyPart();                  MimeBodyPart line5 = new MimeBodyPart();                  MimeBodyPart line6 = new MimeBodyPart();                  MimeBodyPart line7 = new MimeBodyPart();                      Multipart multipart = new MimeMultipart();                           System.out.println("Total number of Errors at console   from mailer:"+m_toterr);                     //CarParser1.logger.info("Total number of   Errors:"+m_toterr);                    line0.setContent("<body bgcolor=yellow>","text/html");                    line1.setContent("<h4 style=color:blue>Dear   All,</h4>","text/html");                    line2.setContent("<br><br><h4 style=color:red>The       below is the today's CAR Validation status</h4>","text/html");                      line3.setContent("</p>","text/html");                    line4.setContent("</body>","text/html");                        //line3.setContent("<br><h4 style=color:blue>PFA for   the Log File</h4>","text/html");                    //line4.attachFile("D:/logfile.log");                    line4.setContent("<br><br><h4 style=color:blue>     Regards,<br>( E-ops Software ) </h5>","text/html");                    line5.setContent("<br><h4 style=color:red>(Auto mail,   please do not reply)</h4>","text/html");               //     line7.setContent("System.out.println(Total Number of   errors:"+m_toterr);");                      multipart.addBodyPart(line0);                    multipart.addBodyPart(line1);                    multipart.addBodyPart(line2);                    //multipart.addBodyPart(line3);                    multipart.addBodyPart(line4);                    multipart.addBodyPart(line5);                  //  multipart.addBodyPart(line6);                    message.setContent(multipart );                  Transport.send(message);                    System.out.println("Email Sent successfully....");                  CarParser1.logger.info("Email Sent Successfully...");                  System.out.println();              }     

--------------code ends

please help.

No comments:

Post a Comment