• Post Reply Bookmark Topic Watch Topic
  • New Topic

passing html text in a java String object  RSS feed

 
anshul saxena
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I am doing a project which requires me to email a text to the user. In that email, I wish to provide hyperlinks to the request ids generated for the requests that the user makes.
I am using the javax.mail package for the email. I am passing the body of the email as a String object in java.
I wish to use hyperlinks in the text body .
Is there a way to convert this text so that the relevant part may be shown as the hyperlink ?
 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the recipient's e-mail client that makes the hyperlink, not you. But almost all of them will make hyperlinks out of any piece of text that looks like a URL. So just send plain text that happens to contain your URLs. You don't need an HTML-formatted message to do that.
 
anshul saxena
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !
Thanks for the prompt response.
I wish to ask one more question just to confirm that I was clear on the last one.
I am passing the email message text as a string and I have tried to hyperlink using the "<a href> " tag in that String object in java.
The mail content type of the java file has not been set to anything explicitly so I am assuming that it is plain text.
Still in the sent mail, the "<a href>" text is being displayed as a text and not being understood for a hyperlink by the email.
I want to solve this problem. Hope I am clear ! Regards
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, what you want is to send an HTML text as a string. You need to start and end your stream with HTML tags ie., <html> .
 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by anshul saxena:
I am passing the email message text as a string and I have tried to hyperlink using the "<a href>" tag in that String object in java.
No. Don't send any HTML markup. If you want to send a hyperlink to (say) http://www.myorg.com/SpecialOffer then just send the string "http://www.myorg.com/SpecialOffer". (Without the quotes of course.) Almost all mail clients will format that as a hyperlink.
 
anshul saxena
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I will elaborate the problem with an example:
My statement is
String newmessage = "<a href = http://www.yahoo.com>Yahoo!</a>"

I want the text "Yahoo!" above to act as the hyperlink text pointing to the http://www.yahoo.com site as shown above. But when I pass this string, it appears as is.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As stated earlier, it is not YOUR responsibility to make the link act as a hyperlink. The recipient's email client does that. Most modern clients will do this automatically for anything that looks like a URL. You just have to send the URL itself in the contents of the email.

Alternatively, you could set the MIME type of the email to indicate that you are sending HTML. Then you can send a String that contains any HTML tags you wish. Without this, the email client will assume that the body is plain text and will display it as such.

Layne
 
anshul saxena
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lane and Paul , You were absolutely correct about the "setContent" field. I have resolved this issue now. Thanks a million !
Thanks also to ev'one who replied.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!