dcsimg
Creating a MimeMessage from a Inputstream
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Makesh_Rao
Posted On:   Friday, April 19, 2002 01:18 PM

I have written a client code to send a multipart/mixed message, using JavaMail api. The mail seems to be fine as I find it when I dump it to a file. I just write the message to a URL. using the writeTo method of the message. On the server side, I have a servlet that accepts the request. I get the inputstream from the request and create a message out of it : //Create session before this MimeMessage message = new Message(session, request.getInputStream()); //I thought this might help.. MailcapCommandMap map = new MailcapCommandMap(); map.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain"); map.addMailcap("multipart/*;   More>>

I have written a client code to send a multipart/mixed message, using JavaMail api. The mail seems to be fine as I find it when I dump it to a file. I just write the message to a URL. using the writeTo method of the message.



On the server side, I have a servlet that accepts the request. I get the inputstream from the request and create a message out of it :

			
//Create session before this
MimeMessage message = new Message(session, request.getInputStream());



//I thought this might help..
MailcapCommandMap map = new MailcapCommandMap();
map.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
map.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
CommandMap.setDefaultCommandMap(map);

Multipart multipart = (Multipart)message.getContent();
BodyPart bodyPart = ((Multipart)multipart).getBodyPart(0);





When I get to the part where I try to get the Bodypart, I get a
javax.mail.internet.ParseException
. I tried to get the count of the parts in the Multipart. The count returns 0.



If I try to cast the object returned with message.getContent() to a String and print it, it prints the entire message that was sent from the client, including the attachment.



Any ideas ...





Makesh    <<Less

Re: Creating a MimeMessage from a Inputstream

Posted By:   Makesh_Rao  
Posted On:   Wednesday, May 8, 2002 02:36 PM

With a lot of help from Bill Shannon from Sun, I was able to figure out the problem.


The content type had some additional parameters like
type=text/xml ;start=.



I was adding them to the content-type header myself and the mail api on the servlet side was unable to parse it. This was because the values needed to be enclosed in double quotes e.g.
type="text/xml" ;start="".



This solved the problem. I used the ContentType object to add the parameters and was able to solve the problem.


Hope this helps anybody else having this problem.



Makesh
About | Sitemap | Contact