Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

With JavaMail is it possible to add html  RSS feed

bobby, morkos
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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_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();
// 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();
// add the Multipart to the message
Transport.send ( msg );
Gregg Bolinger
Ranch Hand
Posts: 15304
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!