使用JavaMail访问Microsoft Exchange邮箱(IMAP,微软的Exchange) [英] Use Javamail for accessing Microsoft Exchange mailboxes (IMAP, MS Exchange)

查看:3771
本文介绍了使用JavaMail访问Microsoft Exchange邮箱(IMAP,微软的Exchange)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要连接到通过IMAPS JavaMail的Microsoft Exchange服务器。首先,我得到了:

  A1 NO AUTHENTICATE失败。
javax.mail.AuthenticationFailedException:AUTHENTICATE失败。

例外在我的调试器。

然后,我禁用一些认证协议:

  imapProps.setProperty(mail.imaps.auth.plain.disable,真);
imapProps.setProperty(mail.imaps.auth.ntlm.disable,真);
imapProps.setProperty(mail.imaps.auth.gssapi.disable,真);

这是新的异常,我得到(我已经连接了整个日志):

  DEBUG:setDebug:JavaMail的1.4.4版
DEBUG:getProvider()返回javax.mail.Provider [STORE,IMAPS,com.sun.mail.imap.IMAPSSLStore,Sun微系统公司]
DEBUG:mail.imap.fetchsize:16384
DEBUG:mail.imap.statuscachetimeout:1000
DEBUG:mail.imap.appendbuffersize:-1
DEBUG:mail.imap.minidletime:10
DEBUG:禁用AUTH =普通
DEBUG:禁用AUTH = NTLM
DEBUG:启用STARTTLS
DEBUG:尝试连接到主机host.domain.com,端口993,isSSL真
* OK的Microsoft Exchange IMAP4服务就绪。
A0能力的
*能力的IMAP4 IMAP4rev1 AUTH = NTLM AUTH = GSSAPI AUTH =普通UIDPLUS儿童IDLE NAMESPACE LITERAL +
A0 OK能力的完成。
DEBUG IMAP:AUTH:NTLM
DEBUG IMAP:AUTH:GSSAPI
DEBUG IMAP:AUTH:平纹
DEBUG:protocolConnect登录,主机= host.domain.com,user=user@domain.com,密码= LT;非空>
A1 LOGIN user@domain.com密码
A1没有登录失败。
DEBUG:尝试连接到主机host.domain.com,端口993,isSSL真
* OK的Microsoft Exchange IMAP4服务就绪。
A0能力的
*能力的IMAP4 IMAP4rev1 AUTH = NTLM AUTH = GSSAPI AUTH =普通UIDPLUS儿童IDLE NAMESPACE LITERAL +
A0 OK能力的完成。
DEBUG IMAP:AUTH:NTLM
DEBUG IMAP:AUTH:GSSAPI
DEBUG IMAP:AUTH:平纹
DEBUG:protocolConnect登录,主机= host.domain.com,user=user@domain.com,密码= LT;非空>
A1 LOGIN user@domain.com密码
A1没有登录失败。
javax.mail.AuthenticationFailedException:登录失败。
在com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:660)
在javax.mail.Service.connect(Service.java:317)
在javax.mail.Service.connect(Service.java:176)
在ConnectMail.connectMail(ConnectMail.java:63)
在Main.main(Main.java:9)

现在我得到了没有登录失败的异常。

这是我的全code:

 属性imapProps =新特性();
imapProps.setProperty(mail.imaps.socketFactory.port,993);
imapProps.setProperty(mail.imaps.starttls.enable,真);
imapProps.setProperty(mail.imaps.socketFactory.class,javax.net.ssl​​.SSLSocketFactory);
imapProps.setProperty(mail.imaps.socketFactory.fallback,假);
imapProps.setProperty(mail.imaps.auth.plain.disable,真);
imapProps.setProperty(mail.imaps.auth.ntlm.disable,真);
imapProps.setProperty(mail.imaps.auth.gssapi.disable,真);
imapProps.setProperty(用户名,user@domain.com);
imapProps.setProperty(密码,密码);字符串主机=host.domain.com;
INT端口=的Integer.parseInt(993);身份验证身份验证=新的Authenticator(){
    受保护的PasswordAut​​hentication的getPasswordAut​​hentication(){
        返回新的PasswordAut​​hentication(user@domain.com,密码);
    }
};会话= Session.getInstance(imapProps,认证);session.setDebug(真);店中店= session.getStore(IMAPS);store.connect(主机,user@domain.com,密码);


解决方案

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

此外,请参阅常见的错误的

I need to connect to a Microsoft Exchange Server through IMAPS JavaMail. First, I got the:

A1 NO AUTHENTICATE failed.
javax.mail.AuthenticationFailedException: AUTHENTICATE failed.

exception in my debugger.

Then, I disabled some authentication protocols:

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

This is the new exception I'm getting (I've attached the whole log):

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=<non-null>
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=<non-null>
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)

Now I'm getting the "NO LOGIN failed" Exception.

This is my full code:

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");

解决方案

You need to use a newer version of JavaMail that supports NTLM authentication. The latest version is 1.5.1.

Also, see this list of common mistakes.

这篇关于使用JavaMail访问Microsoft Exchange邮箱(IMAP,微软的Exchange)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆