how to ignore server cert error in javamail

后端 未结 10 1318
长发绾君心
长发绾君心 2020-12-05 07:12

when i connect to my imap server using imaps,it failes.

can you tell me how to ignore server cert error in javamail

Exception in thread \"main\"
java         


        
10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-05 08:00

    This will help you bypass certificate process and get directly to ssl host

    MailSSLSocketFactory sf = null;
    try
    {
        sf = new MailSSLSocketFactory();
    }
    catch (GeneralSecurityException e)
    {
        e.printStackTrace();
    }
            sf.setTrustAllHosts(true);
    
    Properties pop3Props = new Properties();
    pop3Props.setProperty("mail.pop3.ssl.enable", "true");
    pop3Props.setProperty("mail.protocol.ssl.trust", "pop3.live.com");
    pop3Props.put("mail.pop3s.ssl.socketFactory", sf);
    pop3Props.setProperty("mail.pop3s.port", "995");
    
    Session session = Session.getInstance(pop3Props);
    
    try
    {
    /* Get a Store object*/
       Store store = session.getStore("pop3s");
    //process further activity 
    }
    

提交回复
热议问题