为什么我不能使用JavaMail(IMAP协议)连接到我的邮箱,并收到“没有身份验证失败”错误消息?

时间:2019-06-12 14:55:40

标签: java javamail imap

我正在尝试通过JavaMail IMAP协议连接到邮箱,但无法成功连接。

  1. telnet成功
  2. 能够使用相同的凭据配置Outlook Web Client
  3. 尝试使用最新的JavaMail版本1.6.2(JDK7版本)
  4. 也尝试设置以下属性:mail.imap.auth.plain.disable=true
Properties props = System.getProperties();
props .setProperty("mail.store.protocol", "imap");
props .setProperty("mail.debug.auth", "true");
props .setProperty("mail.imap.ssl.enable", "true");
props .setProperty("mail.imap.auth.plain.disable", "true");
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(UserName, Password);
                }
            });
session.setDebug(true);
store = session.getStore("imap");
store.connect(ServerName, Port, UserName, Password);
DEBUG: setDebug: JavaMail version 1.6.2
DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle]
DEBUG IMAP: mail.imap.fetchsize: 16384
DEBUG IMAP: mail.imap.ignorebodystructuresize: false
DEBUG IMAP: mail.imap.statuscachetimeout: 1000
DEBUG IMAP: mail.imap.appendbuffersize: -1
DEBUG IMAP: mail.imap.minidletime: 10
DEBUG IMAP: closeFoldersOnStoreFailure
2019-06-12 20:10:11 imap : Before connect
DEBUG IMAP: trying to connect to host "<mail-server>", port 993, isSSL true
* OK The Microsoft Exchange IMAP4 service is ready.
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=NTLM AUTH=GSSAPI SASL-IR UIDPLUS MOVE ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
A0 OK CAPABILITY completed.
DEBUG IMAP: AUTH: PLAIN
DEBUG IMAP: AUTH: NTLM
DEBUG IMAP: AUTH: GSSAPI
DEBUG IMAP: protocolConnect login, host=<mail-server>, user=username, password=<non-null>
DEBUG IMAP: mechanism PLAIN disabled by property: mail.imap.auth.plain.disable
DEBUG IMAP: mechanism LOGIN not supported by server
A1 AUTHENTICATE NTLM
+ 
DEBUG NTLM: type 1 message: 4E 53 50 00 01 00 00 00 03 A2 00 00 00 00 00 00 2F 00 00 00 0F 00 0F 00  
<NTLMSSL encoded data>
A1 NO AUTHENTICATE failed.
DEBUG IMAP: trying to connect to host "<mail-server>", port 993, isSSL true
* OK The Microsoft Exchange IMAP4 service is ready.
B0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=NTLM AUTH=GSSAPI SASL-IR UIDPLUS MOVE ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
B0 OK CAPABILITY completed.
DEBUG IMAP: AUTH: PLAIN
DEBUG IMAP: AUTH: NTLM
DEBUG IMAP: AUTH: GSSAPI
DEBUG IMAP: protocolConnect login, host=<mail-server>, user=username, password=<non-null>
DEBUG IMAP: mechanism PLAIN disabled by property: mail.imap.auth.plain.disable
DEBUG IMAP: mechanism LOGIN not supported by server
B1 AUTHENTICATE NTLM
+ 
DEBUG NTLM: type 1 message: 4E 54 4C 53 45 4F 4C 56 41 44 53 52 56 30 39 31 
<NTLMSSL encoded data>
B1 NO AUTHENTICATE failed.
javax.mail.AuthenticationFailedException: AUTHENTICATE failed.
        at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:732)
        at javax.mail.Service.connect(Service.java:388)
        at com.maildebug.MailDebugUtil.Pop3_IMAP(MailDebugUtil.java:131)
        at com.maildebug.MailDebugUtil.main(MailDebugUtil.java:67)

2 个答案:

答案 0 :(得分:1)

几乎可以肯定,您会遇到Exchange服务器错误,该错误表明它支持PLAIN身份验证,但实际上不支持。

调试输出未显示您已禁用PLAIN身份验证,也许您在设置该属性方面做错了什么?您能否包含您实际使用的代码,以显示您如何设置属性?

还要注意您don't need the Authenticator

答案 1 :(得分:1)

由于交换服务器停止通信并导致此问题,因此IMAP协议更改为IMAPI4。我们已经还原了这些更改。现在,问题解决了。