Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to create a MimeBodyPart properly with an InputStream in the constructo

843834Apr 15 2009 — edited Jul 20 2009
I am looping through a list of email attachments.
In this loop I am doing the following:
(Don't worry about the Core object, it works and returns a valid InputStream, tested this before by just reading out the bytes)

		  	InputStream attachInputStream = Core.getFileDocumentContent(attachObject);
		    	System.out.println("available for original stream: " + attachInputStream.available());
		    	MimeBodyPart attachmentBodyPart = new MimeBodyPart(attachInputStream);
		    	InputStream testStream = attachmentBodyPart.getInputStream();
		    	System.out.println("available for retrieved stream: " + testStream.available());

		    	attachmentBodyPart.setFileName(attachment.getName());
			multipart.addBodyPart(attachmentBodyPart);
Because my received attachments were always empty, I added a few println's to check where this were going wrong. Following is the output when I run the application:

available for original stream: 119
available for retrieved stream: 0

So, apparently something goes wrong in the constructor for MimeBodyPart.

I hope I'm just doing something silly but I'm out of options at the moment apart of writing a lot of extra code to handle converting an InputStream to a MimeBodypart myself.

Anyone with some ideas?

edit: I just read I cannot use available after getting an inputstream from a mimebodypart. So I'll go and make another check. Problem still exists though, I'm not getting an attachment after mailing it.

Edited by: Bas_Rotterdam on Apr 15, 2009 3:16 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 17 2009
Added on Apr 15 2009
3 comments
436 views