笔者用的是javax.mail-1.6.2.jar
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed的异常:
在创建MimeMessage message=new MimeMessage(session);之前加上Thread.currentThread().setContextClassLoader(javax.mail.Message.class.getClassLoader());这句代码示例如下
Thread.currentThread().setContextClassLoader(javax.mail.Message.class.getClassLoader());
MimeMessage message=new MimeMessage(session);
此效果不同的工程有不同的解决办法,有的是再发邮件之前让添加如下代码笔者试了不管用。
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);
此问题笔者查了一上午在网上翻了很多资料。煞费苦心希望可以帮助到大家