【问题标题】:secure imap connection in javajava中的安全imap连接
【发布时间】:2012-01-25 18:19:44
【问题描述】:

我正在尝试使用我在以下位置找到的 java 程序连接到侦听端口 993 的 imap 服务器:

http://harikrishnan83.wordpress.com/2009/01/24/access-gmail-with-imap-using-java-mail-api/

我在 Ubuntu 上运行这个程序。 但是,我对此感到异常:

DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc]
DEBUG: mail.imap.fetchsize: 16384
javax.mail.MessagingException: Unrecognized SSL message, plaintext connection?;
  nested exception is:
    javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
    at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:479)
    at javax.mail.Service.connect(Service.java:275)
    at javax.mail.Service.connect(Service.java:156)
    at org.myorg.IMAP.main(IMAP.java:40)
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
    at com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(InputRecord.java:523)
    at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:355)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:798)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1138)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:753)
    at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
    at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
    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

在这篇文章的最后,他们建议: 看来您必须将 imap 服务器的证书添加到受信任的证书存储中

  1. 下载 imap 服务器的证书
  2. 找到您的 cacerts 文件
  3. 使用 keytool 将证书导入到您的 cacerts 文件中

但是,我无法理解如何为在 Windows 机器上运行的 IMAP 服务器执行这些步骤。

任何人都可以请。帮帮我吗?

【问题讨论】:

    标签: java ssl imap


    【解决方案1】:

    正如错误消息所暗示的,您可能没有连接到 SSL 加密端口,而是连接到纯文本端口。请使用您的实际配置(主机、端口、协议)更新您的问题。

    如果您缺少证书,您将收到完全不同的错误消息。

    【讨论】:

    • 配置如下:Properties props = new Properties(); props.put("mail.imaps.host", "1.2.3.4"); props.put("mail.imaps.auth", "true"); props.put("mail.debug", "true"); props.put("mail.imaps.port", 993); props.put("mail.imaps.socketFactory.port", 993); props.put("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.imaps.socketFactory.fallback", "false");
    • @GregS 有两种方式:连接明文 IMAP(端口 143)并发出 STARTTLS,或通过 SSL 连接端口 993(即 SSL 加密的 IMAP 端口)。它们是相互排斥的。
    • @MarkRotteveel:这很有道理,谢谢马克。我将删除我的评论。
    • 我也有同样的问题。你能在这里展示一下解决方案是什么吗?
    猜你喜欢
    • 2017-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多