Wednesday, 11 March 2009

Java mail MIME type errors

I've developed small job on local machine which sends email with PDF attachments. But when i ran it on test environment, an exception was thrown:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;

While searching the solution, found this question. Solution i found was adding MIME type handlers programmatically:
// add handlers for main MIME types
MailcapCommandMap mc = (MailcapCommandMap)CommandMap.getDefaultCommandMap();
mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");
CommandMap.setDefaultCommandMap(mc);
Others solutions didn't work for me - i had recent activation.jar and mail.jar in WEB-INF/lib folder already. Can someone explain me why META-INF/mailcap file wasn't read from mail.jar?

1 comment:

  1. I'm having the same issue, my working theory is that the "mailcap" resource is loaded by the ClassLoader local to the relevant activation class and this ClassLoader does not have access to the /WEB-INF/lib folder.

    ReplyDelete