1

使用以下代码从 Zimbra 邮件服务器读取邮件。

String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";

Properties pop3Props = new Properties();

pop3Props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
pop3Props.setProperty("mail.pop3.socketFactory.fallback", "false");
pop3Props.setProperty("mail.pop3.auth", "true");
pop3Props.setProperty("mail.pop3.port",  "110");
pop3Props.setProperty("mail.pop3.socketFactory.port", "110");

URLName url = new URLName("pop3", host, 110, "",username, password);

Session session = Session.getInstance(pop3Props, null);
Store store = new POP3SSLStore(session, url);
store.connect();

但不断收到此错误

javax.mail.MessagingException: Connect failed;
  nested exception is:
    javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
    at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:148)
    at javax.mail.Service.connect(Service.java:275)
    at javax.mail.Service.connect(Service.java:156)
    at javax.mail.Service.connect(Service.java:105)
    at VerifyMail.readPOP3(VerifyMail.java:177)
    at VerifyMail.main(VerifyMail.java:20)
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
    at com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(Unknown Source)
    at com.sun.net.ssl.internal.ssl.InputRecord.read(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
    at com.sun.net.ssl.internal.ssl.AppInputStream.read(Unknown Source)
    at java.io.BufferedInputStream.fill(Unknown Source)
    at java.io.BufferedInputStream.read(Unknown Source)
    at java.io.DataInputStream.readLine(Unknown Source)
    at com.sun.mail.pop3.Protocol.simpleCommand(Protocol.java:347)
    at com.sun.mail.pop3.Protocol.<init>(Protocol.java:91)
    at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:201)
    at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:144)
    ... 5 more

任何人都可以帮助解决这个问题吗?

4

2 回答 2

5

阅读此常见错误列表,然后清理您的代码。

Gmail 示例也应该适用于您,但显然您需要更改主机名。

于 2012-09-11T18:52:09.903 回答
0

这将帮助您绕过证书过程并直接访问 ssl 主机

    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 
    }
于 2013-12-19T12:00:25.813 回答