• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to send HTML contents through Java Mail API  RSS feed

 
Rahul Khanna
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am facing a problem in sending HTML contents through Java mail API.
In the message String I wrote
msg.setText(<b>Hello </b> ;
.....and later.......
Transport.send(msg)
But when this message is viewed in the InBox of the reciepent the message recieved was
<b>Hello </b>
whereas I wanted to send Hello in BOLD.
 
Chris Stewart
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your best bet is to create a StringBuffer and have it return a String. Then set the content of your email as the returned String. That way you can have reusable code and a very involved email message without packing to much in a call.
 
Van Glass
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition to that make sure that you set the Content-Type header of your email to text/html ... Otherwise some email clients will render it as HTML and other "may" render it as text.
I think JavaMail does this automatically but also make sure that the body of your message is Quoted-Printable encoded. This will ensure that no unexpected line breaks are entered due to the 74 character per-line limit (can really screw up your HTML if you are not careful)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!