JavaMail无法验证Exchange Server IMAP 4,但Thunderbird是

问题描述

我想通过IMAP支持连接到Exchange Server(2003)。 凭据是正确的,因为我可以通过它进行连接。具有相同设置的Thunderbird。

  • 我使用基于域的凭据
  • SSL证书是自签名的

这是 JavaMail 调试日志:

DEBUG: setDebug: Jakarta Mail version 1.6.5
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle]
DEBUG IMAPS: mail.imap.fetchsize: 16384
DEBUG IMAPS: mail.imap.ignorebodystructuresize: false
DEBUG IMAPS: mail.imap.statuscachetimeout: 1000
DEBUG IMAPS: mail.imap.appendbuffersize: -1
DEBUG IMAPS: mail.imap.minidletime: 10
DEBUG IMAPS: closeFoldersOnStoreFailure
DEBUG IMAPS: protocolConnect returning false,host=mail-intern.example.com,user=MY_USERNAME,password=<null>
DEBUG IMAPS: trying to connect to host "mail-intern.example.com",port 993,isSSL true
* OK The Microsoft Exchange IMAP4 service is ready.
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=NTLM AUTH=GSSAPI UIdplUS MOVE ID CHILDREN IDLE NAMESPACE LIteraL+
A0 OK CAPABILITY completed.
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: AUTH: NTLM
DEBUG IMAPS: AUTH: GSSAPI
DEBUG IMAPS: protocolConnect login,user=DOMAIN\ACCOUNT-ALIAS\SUBACCOUNT-ALIAS,password=<non-null>
A1 AUTHENTICATE PLAIN
+
(BASE64 ENCODED CREDENTIALS)
A1 NO AUTHENTICATE Failed.
[main][ERROR]: imap.ImapMailConnector - Error querying mails
javax.mail.AuthenticationFailedException: AUTHENTICATE Failed.
    at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:708) ~[jakarta.mail-1.6.5.jar:1.6.5]

因为我想知道为什么 Thunderbird 能够连接,所以将其设置为调试模式(https://wiki.mozilla.org/MailNews:Logging#Generating_a_Protocol_Log),结果如下:

D/IMAP ImapThreadMainLoop entering [this=0000012E50098800]
[(null) 22308: Main Thread]: I/IMAP 0000012E50098800:mail-intern.example.com:NA:SetupWithUrlCallback: clearing IMAP_CONNECTION_IS_OPEN
I/IMAP 0000012E50098800:mail-intern.example.com:NA:ProcessCurrentURL: entering
I/IMAP 0000012E50098800:mail-intern.example.com:NA:ProcessCurrentURL:imap://ACCOUNT%40DOMAIN%2Ecom@mail-intern.example.com:993/select%3E/INBox:  = currentUrl
D/IMAP ReadNextLine [rv=0x0 stream=0000012E4C874F70 nb=53 needmore=0]
I/IMAP 0000012E50098800:mail-intern.example.com:NA:CreateNewLineFromSocket: * OK The Microsoft Exchange IMAP4 service is ready.

D/IMAP SetConnectionStatus(0x0)
D/IMAP SetConnectionStatus(0x0)
I/IMAP 0000012E50098800:mail-intern.example.com:NA:SendData: 1 capability

D/IMAP ReadNextLine [rv=0x0 stream=0000012E4C874F70 nb=112 needmore=0]
I/IMAP 0000012E50098800:mail-intern.example.com:NA:CreateNewLineFromSocket: * CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=NTLM AUTH=GSSAPI UIdplUS MOVE ID CHILDREN IDLE NAMESPACE LIteraL+

D/IMAP SetConnectionStatus(0x0)
D/IMAP ReadNextLine [rv=0x0 stream=0000012E4C874F70 nb=28 needmore=0]
I/IMAP 0000012E50098800:mail-intern.example.com:NA:CreateNewLineFromSocket: 1 OK CAPABILITY completed.

D/IMAP SetConnectionStatus(0x0)
D/IMAP Try to log in
D/IMAP IMAP auth: server caps 0x41187635,pref 0x1006,Failed 0x0,avail caps 0x1004
D/IMAP (GSSAPI = 0x1000000,CRAM = 0x20000,NTLM = 0x100000,MSN = 0x200000,PLAIN = 0x1000,LOGIN = 0x2,old-style IMAP login = 0x4,auth external IMAP login = 0x20000000,OAUTH2 = 0x800000000)
D/IMAP Trying auth method 0x1000
D/IMAP got new password
D/IMAP IMAP: trying auth method 0x1000
D/IMAP PLAIN auth
I/IMAP 0000012E50098800:mail-intern.example.com:NA:SendData: 2 authenticate PLAIN

D/IMAP ReadNextLine [rv=0x0 stream=0000012E4C874F70 nb=3 needmore=0]
I/IMAP 0000012E50098800:mail-intern.example.com:NA:CreateNewLineFromSocket: +

D/IMAP SetConnectionStatus(0x0)
I/IMAP 0000012E50098800:mail-intern.example.com:NA:SendData: Logging suppressed for this command (it probably contained authentication information)
D/IMAP ReadNextLine [rv=0x0 stream=0000012E4C874F70 nb=27 needmore=0]
I/IMAP 0000012E50098800:mail-intern.example.com:NA:CreateNewLineFromSocket: 2 NO AUTHENTICATE Failed.

D/IMAP SetConnectionStatus(0x0)
D/IMAP authlogin Failed
D/IMAP Marking auth method 0x1000 Failed
D/IMAP IMAP auth: server caps 0x41187635,Failed 0x1000,avail caps 0x4

可以看到,雷鸟也因为AUTH=PLAIN而失败, 但是它会尝试通过old-style IMAP login = 0x4进行身份验证,然后才能进行身份验证,即使Exchange Server(AUTH=PLAIN AUTH=NTLM AUTH=GSSAPI尚未正式支持它也是如此)。

D/IMAP (GSSAPI = 0x1000000,OAUTH2 = 0x800000000)
D/IMAP Trying auth method 0x4
D/IMAP got new password
D/IMAP IMAP: trying auth method 0x4
D/IMAP old-style auth
I/IMAP 0000012E50098800:mail-intern.example.com:NA:SendData: Logging suppressed for this command (it probably contained authentication information)
D/IMAP ReadNextLine [rv=0x0 stream=0000012E4C874F70 nb=23 needmore=0]
I/IMAP 0000012E50098800:mail-intern.example.com:NA:CreateNewLineFromSocket: 4 OK LOGIN completed.

D/IMAP SetConnectionStatus(0x0)
D/IMAP login succeeded
  • 有人知道什么是老式IMAP登录吗?
  • 我可以在JavaMail中启用它吗?
  • 还有另一个支持功能的库吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)