javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed; boundary

前端 未结 11 2392
暖寄归人
暖寄归人 2020-12-03 17:01

Currently I\'m inline of writing a code that will be listening to a directory. when the directory is updated with .apk file, I\'ll send a mail with this .apk file to a gmail

相关标签:
11条回答
  • 2020-12-03 17:26

    Even I had faced same issue. I tried different versions of javamail it didnt work. The problem was Transport.send() was using MailCapCommandMap class from the default java jdk (JAVA 8 in my case) that loaded outdated mailcap files.

    So I used the latest version of JAVA after which it used MailCapCommandMap from the activation package which loaded the correct mailcap file.

    If any anyone faces same problem in future just add a breakpoint in MailCapCommandMap classes available so that u know which mailcap file it is using.

    0 讨论(0)
  • 2020-12-03 17:30

    Adding the current thread before sending the email is the solution:

    Thread.currentThread().setContextClassLoader( getClass().getClassLoader() );
    
    0 讨论(0)
  • 2020-12-03 17:36

    JavaMail depends on some configuration files to map MIME types to Java classes (e.g., multipart/mixed to javax.mail.internet.MimeMultipart). These configuration files are loaded using the ClassLoader for the application. If the ClassLoader doesn't function properly, these configuration files won't be found.

    You can simply add below lines .. that solves the issue .

    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"); 
    
    0 讨论(0)
  • 2020-12-03 17:36

    I am busy converting a Java 8 project to Java 10. At the same time I have been updating all of the dependencies. I was getting a similar exception and none of the above solutions worked for me.

    I have the following in my pom.xml:

    <dependency>
        <groupId>com.sun.mail</groupId>
        <artifactId>javax.mail</artifactId>
        <version>1.6.1</version>
    </dependency>
    

    I did a bit more research and found the following link:

    http://www.jguru.com/faq/view.jsp?EID=237257

    So I tried adding the following dependency to my pom.xml:

    <dependency>
        <groupId>javax.activation</groupId>
        <artifactId>activation</artifactId>
        <version>1.1.1</version>
     </dependency>
    

    That fixed the problem, I was able to send mail with attachments again.

    0 讨论(0)
  • 2020-12-03 17:37

    This issue can get a solution by taking up the below two steps.

    1. Make sure java mail is 1.4.7.(Previously I used 1.4.5 which led to all confusions). Download it from http://www.oracle.com/technetwork/java/index-138643.html
    2. Add this piece of code before sending the message:
        Thread.currentThread().setContextClassLoader( getClass().getClassLoader() );
    
    0 讨论(0)
  • 2020-12-03 17:38

    If your build.xml does this: zipfileset src="javamail-1.4.7/mail.jar" excludes="META-INF/"**

    Then you're stripping out the configuration information.

    0 讨论(0)
提交回复
热议问题