Javamail NTLM身份验证失败

编程入门 行业动态 更新时间:2024-10-23 01:38:01
本文介绍了Javamail NTLM身份验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

尝试在JavaMail中使用NTLM连接到Exchange服务器。我可以连接到SMTP,但不能连接到IMAP。我还可以通过OS X Mail.app应用程序使用相同的主机/用户名/密码,帐户类型=IMAP,端口143,ssl = false,身份验证= NTLM,域名=进行身份验证。

Trying to connect to Exchange server using NTLM in JavaMail. I can connect to SMTP, but not IMAP. I can also authenticate via the OS X Mail.app application using the identical host/username/password, account type = "IMAP", Port 143, ssl=false, authentication=NTLM, Domain Name="".

连接代码:

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"; 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", port 25, isSSL false 220 server18.example 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", port: 25 EHLO 192.168.1.107 250-server18.example 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", port 143, isSSL false * OK server18.example 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, 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

我尝试用反斜杠包装用户名,每 www.oracle/technetwork/java/faq-135477.html#Exchange-login 我收到以下错误:

I tried wrapping the username with backslashes, per www.oracle/technetwork/java/faq-135477.html#Exchange-login I get the following error:

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

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

Backslashes around the username in the SMTP connect portion cause it to fail. I can't tell if the "One time use" error is a step in the right direction or not.

推荐答案

我有注意到 - 通过SMTP - NTLM身份验证不适用于旧版本的javax.mail(最高1.4.1),但它现在适用于1.4.5版本。 要指定的用户名的格式为domain\username。可能是同样的效果(javax.mail版本的差异)也适用于IMAP。

I have noticed that - via SMTP - the NTLM Authentication did not work with an older version of javax.mail (up to 1.4.1) but it now works with version 1.4.5. And the user name to be specified was of the form "domain\username". Could be that same effect (difference in versions of javax.mail) would also apply to IMAP.

更多推荐

Javamail NTLM身份验证失败

本文发布于:2023-11-26 13:03:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633979.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:身份验证   Javamail   NTLM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!