How can we add html contents with mail message
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Rashmy_Sajin
Posted On:   Monday, June 2, 2008 03:45 AM

hi
I have a report in html form and now i want to send that report with mail.i want to know how to add html content with message in the mail.or is there any way to add the url to the message.please help me to do this in jsp and javabeans.
Thanking you
Rashmy

Re: How can we add html contents with mail message

Posted By:   Abdel_Olakara  
Posted On:   Monday, June 2, 2008 05:45 AM

Hi Rashmy,


Sending HTML in mail is very simple. All you need to sent is the proper content type. In your case its "text/html". Have a look at the code below:


fromUser = propFile.getString("me@me.com");
toAddress = propFile.getString("you@you.com");
toAddtokenizer = new StringTokenizer(toAddress,":");
while(toAddtokenizer.hasMoreTokens()){
toAddressArray.add(toAddtokenizer.nextToken());
}
prop = new Properties();
SMTPserver = propFile.getString("testserver.com");
prop.put("mail.smtp.host", SMTPserver);
sess = Session.getDefaultInstance(prop, null);
message = new MimeMessage(sess);
try {
message.setFrom(new InternetAddress(fromUser));
for(int i=0;i message.addRecipient(Message.RecipientType.TO, new InternetAddress(toAddressArray.get(i).toString()));
}
message.setHeader("X-Mailer", "HISOMAILER");
message.setSentDate(new java.util.Date());
message.setSubject(strSubject);
mbp = new MimeBodyPart();
mbp.setContent(msgContent,"text/html");
mp = new MimeMultipart();
mp.addBodyPart(mbp);
message.setContent(mp);
message.saveChanges();
Transport.send(message);



Regards,

Abdel Olakara

http://technopaper.blogspot.com
About | Sitemap | Contact