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.