2

如何通过使用 xoauth 验证 imap 从 gmail 检索邮件。我已经尝试了在 Gmail 数据 api 上为 xoauthAuthenticator.java、xoauthprotocol.java、xoauthsaslclient.java 和 xoauthsaslclienfactory.java 提供的代码

但我有这样的错误

Exception in thread "main" javax.mail.MessagingException: Remote host closed connection during handshake;
  nested exception is:
    javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
    at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:479)
    at javax.mail.Service.connect(Service.java:275)
    at XoauthAuthenticator.connectToImap(XoauthAuthenticator.java:80)
    at XoauthAuthenticator.main(XoauthAuthenticator.java:114)
Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
    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 com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97)
    at java.io.BufferedInputStream.fill(Unknown Source)
    at java.io.BufferedInputStream.read(Unknown Source)
    at com.sun.mail.iap.ResponseInputStream.read0(ResponseInputStream.java:81)
    at com.sun.mail.iap.ResponseInputStream.readResponse(ResponseInputStream.java:67)
    at com.sun.mail.iap.Response.<init>(Response.java:83)
    at com.sun.mail.imap.protocol.IMAPResponse.<init>(IMAPResponse.java:48)
    at com.sun.mail.imap.protocol.IMAPResponse.readResponse(IMAPResponse.java:122)
    at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:230)
    at com.sun.mail.iap.Protocol.<init>(Protocol.java:91)
    at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:87)
    at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:446)
    ... 3 more
Caused by: java.io.EOFException: SSL peer shut down incorrectly
    at com.sun.net.ssl.internal.ssl.InputRecord.read(Unknown Source)
    ... 19 more

这可能是什么原因?

4

1 回答 1

0

当您的 SSLhandler 不信任来自主机服务器的证书时,会引发 SSLHandshakeException。您需要将服务器的 SSL 证书添加到您的密钥库。这是问题的一个很好的演练以及如何解决它。

于 2012-08-03T17:02:06.490 回答