Tuesday, January 6, 2009

"javax.activation.UnsupportedDataTypeException: no object DCH for MIME type xxx/xxxx javax.mail.MessagingException: IOException while sending message;

javax.activation.UnsupportedDataTypeException: no object DCH for MIME type xxx/xxxx javax.mail.MessagingException: IOException while sending message;


I was using a custom Java wrapper class I developed for the background processing of emails from Java apps when I encountered these issues with unhandled MIME types, specifically "text/html" and "multipart/*".

For me, the initial solution was (as suggested in this forum at the outset) providing for these types via the mailcap file (either external or located in the META-INF folder of the distribution jar). However, I subsequently ended up adding the following lines to my email wrapper class:

// 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);


This works fine, and keeps all the relevant dependencies in one place, so I know it will always work irrespective of the overall Java app configuration. Another reason was speed, as the following excerpt from the relevant javadoc proves:

(http://java.sun.com/j2ee/1.4/docs/api/javax/activation/MailcapCommandMap.html)

The MailcapCommandMap looks in various places in the user's system for mailcap file entries. When requests are made to search for commands in the MailcapCommandMap, it searches mailcap files in the following order:

1) Programatically added entries to the MailcapCommandMap instance.
2) The file .mailcap in the user's home directory.
3) The file <java.home>/lib/mailcap.
4) The file or resources named META-INF/mailcap.
5) The file or resource named META-INF/mailcap.default (usually found only in the activation.jar file).

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.