The application is using "ChilkatDotNet4.dll" version.184.108.40.206 email component to save the email attachments to local folder.
The download code works fine for all different file types of attachments except certain pdfs.For some pdf attachments after the attachment is saved locally using Chilkat, the saved pdf document is corrupted and cannot be opened. The error that is received on opening the pdf is "Adobe Reader could not open 'FileName.pdf' because it is either not a supported file type or because the file has been damaged(for example, it was sent as an email attachment ans wasn't correctly decoded)."
Nothing special stands out for the failing pdf attachments. They can be seen in the Outlook mail box opened and saved without any problem (when done through Microsoft Outlook). The mail server is on Microsoft Exchange 2010 and the protocol used is IMAP. Noticed that the size of the file downloaded through Chilkat is more than the actual pdf size in the email.
All the following Chilkat .NET Email methods give the same issue.
File.WriteAllBytes(filepath, email.GetAttachmentData(attachIndex)) OR email.SaveAttachedFile(attachIndex,directory) OR email.SaveAllAttachments(directory)
Where email is of the type Chilkat.Email.
The last error text gives success and it is as follows. Here you can see that bytes are more than the actual file size (223,232 bytes) and therefore the file is corrupted. Not exactly sure where it is getting the extra bytes from. "ChilkatLog: GetAttachmentData: DllDate: Dec 12 2012 UnlockPrefix: XXXXXXX Username: XXXXX:XXXX Architecture: Little Endian; 32-bit Language: .NET 4.0 VerboseLogging: 0 index: 0 numBytes: 317668 Success. --GetAttachmentData --ChilkatLog "
How should this issue be resolved?
It's most likely the PDF is already corrupted within the email. There is nothing within Chilkat that would treat a PDF any differently than any other attachment.
Do this: Save the email to a file by calling SaveEml. Then open the .eml using Thunderbird, save the attachment to a file using Thunderbird, and then check to see if the attachment is valid. If so, then write a quick/simple program using Chilkat to load the .eml from the file and then save the attachment. Is it a valid PDF?
If loading/saving via Thunderbird produces a valid PDF, but loading/saving via Chilkat does not, then send me the .eml in a zipped attachment (to firstname.lastname@example.org)
answered Apr 24 '13 at 10:37