为什么我无法使用JavaMail(IMAP协议)连接到我的邮箱并且没有AUTHENTICATE失败错误?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (76)

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

  1. telnet is successful
  2. Able to configure outlook web client with same credentials
  3. Tried with latest JavaMail version of 1.6.2 (JDK7 version)
  4. Tried setting following property as well : 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>
A1 AUTHENTICATE PLAIN
+ 
<Base64 encoded username+password>
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>
B1 AUTHENTICATE PLAIN
+ 
<Base64 encoded username+password>
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)
提问于
用户回答回答于

您几乎肯定会遇到Exchange服务器错误,它宣称支持普通身份验证,但实际上不支持。

调试输出没有显示您已经禁用了普通身份验证,可能您在设置该属性时做错了什么?您能包括实际使用的代码吗?这些代码显示了如何设置属性?

Note also that you don't need the Authenticator.

扫码关注云+社区

领取腾讯云代金券