用javamail发送附件出错:javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart

只要在调用// 发送邮件

Transport.send(mailMessage);前加上如下代码就行!


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


你可能感兴趣的:(用javamail发送附件出错:javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart)