用javamail发送附件出错:javax.activation.UnsupportedDataTypeException: no object DCH for MIME type text/plain; charset=UTF-8
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart
在Transport.send 语句执行发送前增加以下代码:
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); Thread.currentThread().setContextClassLoader(getClass().getClassLoader());