分享

java mail 发送邮件 no object DCH for MIME type mu...

 欢欢2008 2011-03-13
在本机开发时,邮件没问题,一般也不应该有什么问题,commons_email 和javax.mail搭配很久,低级问题该差不多没了,偏偏上传到服务器上,不行
    javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed
    以前一般都是HTMLMail,这次有附件,因此是MultiPartMail,结果问题就出在这了,去掉附件都不行。
    原因其实也能估计个大概,再加上异常的信息,一定又是MIME的问题,与web application里WEB-INF/web.xml里没有指定application holder一样的道理,可是在MultiPartMail里如何指定呢
放狗
查出来要在本地设置mailcap,无效,再说了,本地也没设置,不应该是这个问题。
再查,一般认为是javax.activation和jdk6的问题,可是我两边都一样的版本,不是
可是这个东西是在哪指定的呢,查jar包里的META-INF,发现activation有mailcap.default, mail.jar有mailcap,而本地没有activation也运行正常,应该是打包的问题。
看 build.xml,发现为了避免以前的未知问题,在unjar所有jar并且打包时,剔除了META-INF,记得是为了避免index.list的冲突问题,也是以前ant的bug
应该就是这个问题,重新打包,OK
另外,也可以在mail.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);

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/cindyIBM/archive/2010/05/10/5574229.aspx

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多