aspose file tools
The moose likes Java in General and the fly likes passing html text in a java String object Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "passing html text in a java String object" Watch "passing html text in a java String object" New topic
Author

passing html text in a java String object

anshul saxena
Greenhorn

Joined: Oct 20, 2005
Posts: 8
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
Bartender

Joined: Oct 14, 2005
Posts: 16479
    
    2

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

Joined: Oct 20, 2005
Posts: 8
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

Joined: Mar 17, 2000
Posts: 5782
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> .


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16479
    
    2

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

Joined: Oct 20, 2005
Posts: 8
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

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
anshul saxena
Greenhorn

Joined: Oct 20, 2005
Posts: 8
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: passing html text in a java String object
 
Similar Threads
SEAM email generation
Struts Tiles Question
Image to String to Image in a email
JavaMail won't send mail
Insert HyperLinks at Email Body