Javamail NTLM身份验证失败

尝试使用JavaMail中的NTLM连接到Exchange服务器。我可以连接到SMTP,但不能连接到IMAP。我还可以使用相同的主机/用户名/密码通过OS

X Mail.app应用程序进行身份验证,帐户类型=“ IMAP”,端口143,ssl = false,authentication =

NTLM,域名=“。

连接代码:

import javax.mail.Session;

import javax.mail.Transport;

import javax.mail.Store;

import java.util.Properties;

public class NTLMTest {

public static void main(String[] args) throws Exception {

final String host = "example.com";

final String user = "bob";

final String password = "password";

final Properties properties = new Properties();

Session session = Session.getDefaultInstance(properties);

session.setDebug(true);

// SMTP CONNECT

final Transport transport = session.getTransport("smtp");

transport.connect(host, user, password);

System.out.println("SMTP Connect successful");

// IMAP CONNECT

final Store store = session.getStore("imap");

store.connect(host, user, password);

System.out.println("IMAP Connect Successful");

}

}

输出:

DEBUG: setDebug: JavaMail version 1.4.3

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]

DEBUG SMTP: useEhlo true, useAuth false

DEBUG SMTP: trying to connect to host "example.com", port 25, isSSL false

220 server18.example.com ESMTP Sendmail 8.14.3/8.14.3/Debian-5+lenny1; Thu, 2 Dec 2010 18:05:30 +0100; (No UCE/UBE) logging access from: xxx.xxx.xxx.xxx

DEBUG SMTP: connected to host "example.com", port: 25

EHLO 192.168.1.107

250-server18.example.com Hello c-xxxx [xxx.xxx.xxx.xxx], pleased to meet you

250-ENHANCEDSTATUSCODES

250-PIPELINING

250-8BITMIME

250-SIZE 20971520

250-DSN

250-ETRN

250-AUTH DIGEST-MD5 CRAM-MD5 LOGIN PLAIN

250-STARTTLS

250-DELIVERBY

250 HELP

DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""

DEBUG SMTP: Found extension "PIPELINING", arg ""

DEBUG SMTP: Found extension "8BITMIME", arg ""

DEBUG SMTP: Found extension "SIZE", arg "20971520"

DEBUG SMTP: Found extension "DSN", arg ""

DEBUG SMTP: Found extension "ETRN", arg ""

DEBUG SMTP: Found extension "AUTH", arg "DIGEST-MD5 CRAM-MD5 LOGIN PLAIN"

DEBUG SMTP: Found extension "STARTTLS", arg ""

DEBUG SMTP: Found extension "DELIVERBY", arg ""

DEBUG SMTP: Found extension "HELP", arg ""

DEBUG SMTP: Attempt to authenticate

DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM

AUTH LOGIN

334 VXNlcm5hbWU6

YWR2aWVzZW5raWVzMDU=

334 UGFzc3dvcmQ6

ZGlja2hvbmluZw==

235 2.0.0 OK Authenticated

SMTP Connect successful

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

DEBUG: mail.imap.fetchsize: 16384

DEBUG: mail.imap.statuscachetimeout: 1000

DEBUG: mail.imap.appendbuffersize: -1

DEBUG: mail.imap.minidletime: 10

DEBUG: trying to connect to host "example.com", port 143, isSSL false

* OK server18.example.com Cyrus IMAP4 v2.1.18-IPv6-Debian-2.1.18-5.1 server ready

A0 CAPABILITY

* CAPABILITY IMAP4 IMAP4rev1 ACL QUOTA LITERAL+ MAILBOX-REFERRALS NAMESPACE UIDPLUS ID NO_ATOMIC_RENAME UNSELECT CHILDREN MULTIAPPEND SORT THREAD=ORDEREDSUBJECT THREAD=REFERENCES IDLE AUTH=DIGEST-MD5 AUTH=NTLM AUTH=CRAM-MD5 ANNOTATEMORE

A0 OK Completed

IMAP DEBUG: AUTH: DIGEST-MD5

IMAP DEBUG: AUTH: NTLM

IMAP DEBUG: AUTH: CRAM-MD5

DEBUG: protocolConnect login, host=example.com, user=bob, password=<non-null>

DEBUG NTLM: type 1 message: Type1Message[suppliedDomain=,suppliedWorkstation=192.168.1.107,flags=0x00000201]

DEBUG NTLM: type 1 message length: 45

A1 AUTHENTICATE NTLM

+

TlRMTVNTUAABAAAAASIAAAAAAAAAAAAADQANACAAAAAxOTIuMTY4LjEuMTA3

+ TlRMTVNTUAACAAAAAAAAADAAAAABIgAApdhJrA6NzmwAAAAAAAAAAAAAAAAAAAAA

TlRMTVNTUAADAAAAGAAYAEAAAAAwADAAWAAAAAAAAAAAAAAAHAAcAIgAAAAaABoApAAAAAAAAAAAAAAAAQIAALV6mIutJKdZSH4IZGmvNqNFxJafzInd0yJDR4J3oe3LyBls0Y75UuwBAQAAAAAAANAS9yNDkssBVbH5v087iUIAAAAAAAAAAGEAZAB2AGkAZQBzAGUAbgBrAGkAZQBzADAANQAxADkAMgAuADEANgA4AC4AMQAuADEAMAA3AA==

A1 NO authentication failure

Exception in thread "main" javax.mail.AuthenticationFailedException: authentication failure

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

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

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

at com.prosc.emailplugin.NTLMTest.main(NTLMTest.java:25)

Disconnected from the target VM, address: '127.0.0.1:56125', transport: 'socket'

Process finished with exit code 1

我尝试通过http://www.oracle.com/technetwork/java/faq-135477.html#Exchange-

login用反斜杠包装用户名,出现以下错误:

Exception in thread "main" javax.mail.AuthenticationFailedException: One time use of a plaintext password will enable requested mechanism for user

SMTP连接部分中用户名周围的反斜杠导致其失败。我无法确定“一次性使用”错误是否朝着正确的方向迈出了一步。

回答:

我注意到-通过SMTP-

NTLM身份验证不适用于旧版本的javax.mail(最高1.4.1),但现在可用于版本1.4.5。并且要指定的用户名的格式为“域\用户名”。可能是同样的效果(javax.mail版本不同)也适用于IMAP。

以上是 Javamail NTLM身份验证失败 的全部内容, 来源链接: utcz.com/qa/428469.html

回到顶部