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!

Sending a PDF document as a file attachment

843830Feb 2 2006 — edited Feb 9 2006
Hi,

I have encountered the following problem:

When attaching a pdf document to an email and sending it via Javamail, the resulting PDF document on the other end (i.e. when opened via an email client, such as Outlook) is corrupted and cannot be opened in Acrobar Reader. When doing a side by side comparison with the original file, the emailed document is 1 byte larger than the original (which can possibly cause the "corrupted file error").

Now, this is happening in my company's application and is happening to only one of our customers. This does not happen to 99.9% of them nor can we duplicate it. In addition, it does not happen to all PDF documents, only a few of them.

I have also ensured that our client has the latest version of Javamail and the activation framework jar files.

One thing I have noticed is that the documents are "encoded" as 7bit. This makes sense since the Javadocs explain that if a file is "US-ASCII only" it will be encoded as 7bit, otherwise it will be encoded as base64. Many of our PDF documents are text only.

My side question is, is there a way to force it to encode it as base64 for all pdf documents and would this help?

My main question is: Does anyone know what is happening and what I can do about it?

Anyway, here is the code fragment that does the attachment:
	  			for (int i = 0; i < attachments.length; i++)
				{
					messageBodyPart = new MimeBodyPart();
					FileDataSource fileDataSource = new FileDataSource(attachments);
messageBodyPart.setDataHandler(new DataHandler(fileDataSource));
String fileName = attachments[i].getName();
messageBodyPart.setFileName(fileName);
multipart.addBodyPart(messageBodyPart);
}


Where attachments is a File array.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 9 2006
Added on Feb 2 2006
4 comments
390 views