aspose file tools*
The moose likes Java in General and the fly likes With JavaMail is it possible to add html Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "With JavaMail is it possible to add html " Watch "With JavaMail is it possible to add html " New topic
Author

With JavaMail is it possible to add html

bobby, morkos
Ranch Hand

Joined: Jan 04, 2002
Posts: 82
For message I want to add html instead of String
msg.setText ( message );
Is it possible and how do I modify my code below to take into account these changes. It would be better if I can point to an html page template [template.html] and automatically setText for that html template.
I have the following code:
Properties properties = new Properties ( );
properties.put ( "mail.smtp.host", mail_server_host );
MimeMessage msg = new MimeMessage (
Session.getInstance ( properties, authenticator ) );
msg.addFrom ( addresses_from );
msg.setRecipients ( Message.RecipientType.TO , addresses_to );
msg.setSubject ( subject );
// for message I want to add html problem here, is there a way to change String into HTML
msg.setText ( message );
// set the Date: header
msg.setSentDate(new Date());
// add attachment
// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(message);
// create the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
// attach the file to the message
FileDataSource fds= new FileDataSource(filePath);
mbp2.setDataHandler( new DataHandler(fds));
mbp2.setFileName( fileName );

Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
Transport.send ( msg );
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Maybe you could try creating a string that includes HTML. I know you can use it for the String Text in a JLabel and JButton, etc.
Something like:
String htmlString = "<HTML>html code here</HTML>";
I haven't tried it, but let me know if it works or not.


GenRocket - Experts at Building Test Data
 
Consider Paul's rocket mass heater.
 
subject: With JavaMail is it possible to add html