MessagingExceptionIOException while sending message in java?

前端 未结 8 999
说谎
说谎 2021-01-19 02:41

I use the following code to send mail.Text message sending is working fine but Mail with attachment is not working it gives the Exception.How to solve this

8条回答
  •  無奈伤痛
    2021-01-19 03:17

    Use that code put that code and then chek that is really works. Frist, import that package

    import javax.activation.CommandMap;
    import javax.activation.MailcapCommandMap;
    
    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);
    

提交回复
热议问题