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!

Corrupted Attachments if not text/html

843830Oct 21 2002 — edited Oct 21 2002
Hello all. I've seen many many posts concerning creating attachments to email messages. I have been able to do this without too much problem.

However, binary attachments always show up corrupted. Plain text attachments are fine. For example, a .doc attachment will be recognized by Word, but if you attempt to open it up, I get a 'Invalid path or filename' error. The primary difference between my situation and one that I have seen posted many times here is that I am not using either a File data source nor a Url data source. I have blobs stored in Oracle and simply have been attempting to create a new MimeBodyPart using the byte[] array I get back from Oracle and a blank InternetHeaders. I initially belived this to be a Content-Type issue, but I have attempted setting the Content-Type for the InternetHeaders object without success.

I know that the byte[] comprising the documents are OK; if I take an intermediate step and write the bytes out to the OS, then use a file data source to create the attachment, I can send it out and the client can read it no problem.

Can anyone help?
Thanks!
brian

Sampe Code below:

for (int z=0;z<attachments.length;z++){
SendMail.Attachment currentAttachment = attachments[z];

InternetHeaders blankHeader = new InternetHeaders();
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
blankHeader.addHeader("Content-Type", currentAttachment.getContentType().toLowerCase());
attachmentBodyPart = new MimeBodyPart(blankHeader, currentAttachment.getByteContents());

MimePartDataSource source = new MimePartDataSource(attachmentBodyPart);
attachmentBodyPart.setDataHandler(new DataHandler(source));
attachmentBodyPart.setFileName(currentAttachment.getFilename());
multipart.addBodyPart(attachmentBodyPart);
}


Again, everything appears to work fine except that I cannot open the files when they arrive.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 18 2002
Added on Oct 21 2002
1 comment
162 views