Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes Java mail contentType.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Java mail contentType.." Watch "Java mail contentType.." New topic
Author

Java mail contentType..

Mandy Smith
Ranch Hand

Joined: Jun 26, 2001
Posts: 62
How to set the java mail content type dynamically? I am using java mail package to do this. Right now, i am getting around this by having a little checkbox at the bottom of the body of the message, if they check html, then the email body contentType is set to "text/html", other wise it isset to plain text.
So my question, if i don't have this checkbox option and sometimes i want to send html and other times i want to send just plain text. Is this possible to dynamically set the contentType?
Could someone help me on this.
Appreciate your help.
Thanks
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Umm, it sounds as if you are setting the content dynamically, in response to user input. Do you mean that you want to set the content-type based on some analysis of the content? Or do you have some other rule in mind for when it should be text/plain and when text/html?
Please explain under which conditions you would like the content-type set to html and when you would like to use plain text.
My own bias would be to always send as plain text: I detest HTML email, but I'll try to put that aside for this discussion.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Mandy Smith
Ranch Hand

Joined: Jun 26, 2001
Posts: 62
I want to have Email as separate class, which has send() method. When i want to send email, i will instantiate this Email class and call its send() method.
I want this email class to be html enabled and if in case i send just plain text, it should not wrap around the text, if the simple text message is in 2 lines.(for eg:- '\n' should be recognized).
Any further help on this?
Appreciate your response Frank Carver.
Thanks.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
OK. If your "send" method has to detect whether the content should be sent as HTML or not based on examining the content, you will have to decide on the precise rules it should follow. Computers are not good at "common sense".
We seem to have one example rule so far: If it is two lines, separated by '\n', then it is plain text. I suggest that that is not enough for a real system. Should every message of three lines or more be sent as HTML ?
You have to make these rules up, and although people may be able to suggest possible situations, it's up to you to finally decide which rules to tell your software. There is no "standard" way that I am aware of for making this decision.
Mandy Smith
Ranch Hand

Joined: Jun 26, 2001
Posts: 62
Thanks. But, i wonder how microsoft outlook handles it!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java mail contentType..