Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Mail content contains html special characters

 
Zaferullah Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am faced with an issue with javamail. I have set the mail content type as 'text/html'. When the body content of mail contains html special characters such as <, >, & etc the content in the mail ends at the first instance of such characters. The rest of the content is not delivered in the mail.

Any inputs on solving this issue will be highly appreciated.

Thanks,
Zafer
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use the official HTML escape sequences: &quot; for ", &lt; for <, &gt; for > and &amp; for & (all start with & and end with ;)
 
Zaferullah Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This can be done but searching and replacing for all such characters in the code will be cumbersome. Are there any simpler and cleaner solution for doing this?

Thanks,
Zafer
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you know that the message body is truncated? Perhaps you are just sending malformed HTML and the e-mail program which tries to display it stops displaying at the first place there's an error. Or perhaps it doesn't, perhaps it interprets your < character as the start of a non-existent HTML element. Find out what the problem is before you start fixing it; for example use several different e-mail programs to see what's really happening.
 
Zaferullah Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,
Yes as you have guessed it, the mail content truncates when a < character is present in it. To be more specific, I am facing this issue when sending a generated password to the user's mail ID. The generated password contains special characters such as < in it.

Thanks,
Zafer
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you'll have to look at your source code to see why it's doing that. It must be your source code because JavaMail doesn't do any validation of a message part which you claim to be HTML.

Of course while you're doing that, you might as well fix the part of your code which is generating malformed HTML, as Rob Prime suggested. That could only help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!