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


Currently I am inline to write a code that will be listening to a directory. When the directory If the APK is updated with the file, then I will send an email to the .apk file with a Gmail account. I am using Jontifie and Java Mail in my program.

I am getting the error,

  javax.mail.MessagingException: when sending a message to IOException; The nested exception is: javax.activation.UnsupportedDataTypeException: MIME type multicolored / mixed to an object DCH; I searched for solutions in Stack Overflow for help, but none of them was helpful   

P> Thanks in advance

  Public Zero File Ready (int wd, string root path, string name) {print ("created" + rootpath + ":" + name); If (name.contains (".apk")) SendEmail (name); Else System.out.println ("no APK file"); } Zero SendEmail (String Strandem) {String Path = "D: / POC / Email / APK Folder /" + strname; System.out.println ("path->" + path); Properties PRO = new property (); Props.put ("mail.smtp.host", "173.194.78.108"); Props.put ("mail.smtp.socketFactory.port", "465"); Props.put ("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); Props.put ("mail.smtp.auth", "true"); Props.put ("mail.smtp.port", "465"); System.out.println ("Properties have been set correctly"); Session session = session .getDefaultInstance (support, new javax.mail.Authenticator () {secure passwordAdvanced getPasswordAuthentication ()} new passwordExtication ("SenderEmailID@gmail.com", "Sender password");}}); System.out.println ("The session was created successfully"); Try {message message = new MimeMessage (session); Message.setFrom (new Internet address ("SenderEmailID@gmail.com")); Message.setRecipients (Message.RecipientType.TO, InternetAddress.parse ("ToReceiverEmailID@gmail.com")); Message.setSubject ("Android:" + strname); MimeBodyPart msgbody = new MimeBodyPart (); Msgbody.setText ("This is message content that is sent using Java mail 1.4.5"); Multipart Mulpart = new mime multipart (); Mulpart.addBodyPart (msgbody); // The attachment starts here Msgbody = new MimeBodyPart (); Javax.activation.DataSource Source = New FileDataSource (Path); Msgbody.setDataHandler (new datahanger (source)); Msgbody.setFileName (strname); Message.setContent (mulpart); System.out.println ("The message that started transporting the mail was attached"); // If the code is being sent before sending an email to me, but without the attachment // ThreadCurrentThread () SetContextClassLoader (getClass (). GetClassLoader ()); Transport.send (message); System.out.println ("Mail successfully sent"); } Catch (Messaging Exposure msg) {msg.printStackTrace (); } Hold (exception e) {e.printStackTrace (); JavaMail depends on some configuration files so that the type of MAM can be stored in Java classes (for example). "Javax.mail.internet.MimeMultipart" from "Multipart / Mixed"). These configuration files are loaded using the classloader for the application. If the class loader does not work properly then these configuration files will not be found.  

You can simply add the lines below .. which resolves this issue.

  MailcapCommandMap mc = (MailCommentMapMap) 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 / RFC 822; x-java-content-handler = com.sun.mail.handlers.message_rfc822");  

Comments