java邮箱exchange_使用Javamail访问Microsoft Exchange邮箱(IMAP,MS Exchange)

我需要通过IMAPS JavaMail连接到Microsoft Exchange Server.首先,我得到了:

A1 NO AUTHENTICATE failed.

javax.mail.AuthenticationFailedException: AUTHENTICATE failed.

我的调试器中的异常.

然后,我禁用了一些身份验证协议:

imapProps.setProperty("mail.imaps.auth.plain.disable", "true");

imapProps.setProperty("mail.imaps.auth.ntlm.disable", "true");

imapProps.setProperty("mail.imaps.auth.gssapi.disable", "true");

这是我得到的新例外(我附上了整个日志):

DEBUG: setDebug: JavaMail version 1.4.4

DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc]

DEBUG: mail.imap.fetchsize: 16384

DEBUG: mail.imap.statuscachetimeout: 1000

DEBUG: mail.imap.appendbuffersize: -1

DEBUG: mail.imap.minidletime: 10

DEBUG: disable AUTH=PLAIN

DEBUG: disable AUTH=NTLM

DEBUG: enable STARTTLS

DEBUG: trying to connect to host "host.domain.com", port 993, isSSL true

* OK The Microsoft Exchange IMAP4 service is ready.

A0 CAPABILITY

* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN UIDPLUS CHILDREN IDLE NAMESPACE LITERAL+

A0 OK CAPABILITY completed.

DEBUG IMAP: AUTH: NTLM

DEBUG IMAP: AUTH: GSSAPI

DEBUG IMAP: AUTH: PLAIN

DEBUG: protocolConnect login, host=host.domain.com, user=user@domain.com, password=

A1 LOGIN user@domain.com password

A1 NO LOGIN failed.

DEBUG: trying to connect to host "host.domain.com", port 993, isSSL true

* OK The Microsoft Exchange IMAP4 service is ready.

A0 CAPABILITY

* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN UIDPLUS CHILDREN IDLE NAMESPACE LITERAL+

A0 OK CAPABILITY completed.

DEBUG IMAP: AUTH: NTLM

DEBUG IMAP: AUTH: GSSAPI

DEBUG IMAP: AUTH: PLAIN

DEBUG: protocolConnect login, host=host.domain.com, user=user@domain.com, password=

A1 LOGIN user@domain.com password

A1 NO LOGIN failed.

javax.mail.AuthenticationFailedException: LOGIN failed.

at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:660)

at javax.mail.Service.connect(Service.java:317)

at javax.mail.Service.connect(Service.java:176)

at ConnectMail.connectMail(ConnectMail.java:63)

at Main.main(Main.java:9)

现在我得到了“NO LOGIN failed”异常.

这是我的完整代码:

Properties imapProps = new Properties();

imapProps.setProperty("mail.imaps.socketFactory.port", "993");

imapProps.setProperty("mail.imaps.starttls.enable", "true");

imapProps.setProperty("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

imapProps.setProperty("mail.imaps.socketFactory.fallback", "false");

imapProps.setProperty("mail.imaps.auth.plain.disable", "true");

imapProps.setProperty("mail.imaps.auth.ntlm.disable", "true");

imapProps.setProperty("mail.imaps.auth.gssapi.disable", "true");

imapProps.setProperty("username", "user@domain.com");

imapProps.setProperty("password", "password");

String host = "host.domain.com";

int port = Integer.parseInt("993");

Authenticator authenticator = new Authenticator() {

protected PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication("user@domain.com", "password");

}

};

session = Session.getInstance(imapProps, authenticator);

session.setDebug(true);

Store store = session.getStore("imaps");

store.connect(host, "user@domain.com", "password");

解决方法:

您需要使用支持NTLM身份验证的较新版本的JavaMail.最新版本是1.5.1.

标签:java,authentication,javamail,imap,exchange-server

来源: https://codeday.me/bug/20190629/1324396.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值