I'm trying to attach a pdf to an email and store it in an imap folder.
I can create and store the email, but I can't get the pdf attachment to work.
I get the error in the subject line.
Here's some exception output:
javax.mail.MessagingException: IOException while appending messages; nested exception is: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type application/pdf at com.sun.mail.imap.IMAPFolder.appendMessages(IMAPFolder.java:1415) at com.yourcompany.EmailAllReportsTask.performAction(EmailAllReportsTask.java:309) at er.extensions.concurrency.ERXLongResponseTask$DefaultImplementation.run(ERXLongResponseTask.java:165) at java.lang.Thread.run(Thread.java:680) at er.extensions.concurrency.ERXLongResponseTask$WorkerThread.run(ERXLongResponseTask.java:63) Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type application/pdf
The error occurs when I try to add the message to the folder (the last line in this code sample) (yes, I'm going direct to the javamail apis at this point):
... // Part two is attachment messageBodyPart = new MimeBodyPart(); // DataSource source = new FileDataSource("smith"); messageBodyPart.setContent(reportOutput, "application/pdf"); messageBodyPart.setHeader("Content-Type", "application/pdf; name=\"ASuperPDF.pdf\""); messageBodyPart.setFileName("ASuperPDF.pdf"); multipart.addBodyPart(messageBodyPart);
// Put parts in message msg.setContent(multipart);
drafts.appendMessages(new Message[] {msg});
I've tried some things I found on the Internets, such as adding this line:
Thread.currentThread().setContextClassLoader( getClass().getClassLoader() );
I was wondering if anybody has run into a similar situation and has a solution.
John
|