I red the JavaMail FAQ and the rest of the threads but none of those helped me resolve my issue.
I'm trying to connect to Exchange Server over IMAP (SSL) on port 993. The Exchange server is configured to accept connections over IMAP (SSL-993 or TLS-143)
This is my source code:
import java.security.Security;
import java.util.Properties;
import javax.mail.Session;
import javax.mail.URLName;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import javax.swing.*;
import java.util.*;
import java.io.*;
import java.security.*;
public class TestSSL {
/**
* @param args
*/
public static void main(String[] args) {
try{
Security.addProvider( new com.sun.net.ssl.internal.ssl.Provider());
String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
//System.setProperty("javax.net.debug", "ssl,handshake");
Properties props = new Properties();
props.setProperty("mail.imap.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.imap.socketFactory.fallback", "false");
props.setProperty("mail.imap.port", "993");
props.setProperty("mail.imap.socketFactory.port", "993");
//props.put("mail.imap.auth.plain.disable","true");
Session session = null;
session = Session.getInstance(props);
session.setDebug(true);
javax.mail.Store store = session.getStore(new
javax.mail.URLName("imap://test@test.com"));
store.connect("imap.test.local",993,"test","myPassword");
}catch (Exception e) {
System.out.println("caught exception: " + e);
e.printStackTrace();
}
}
}
I get the usual
AUTHENTICATE failed. exception.
Debug info:
DEBUG: setDebug: JavaMail version 1.4.3
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 "imap.test.local", port 993, isSSL true
* OK IMAP4 service ready
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN IDLE NAMESPACE LITERAL+
A0 OK CAPABILITY completed.
IMAP DEBUG: AUTH: NTLM
IMAP DEBUG: AUTH: GSSAPI
IMAP DEBUG: AUTH: PLAIN
DEBUG: protocolConnect login, host=imap.test.local, user=test, password=<non-null>
A1 AUTHENTICATE PLAIN
+
<key...>=
A1 NO AUTHENTICATE failed.
caught exception: javax.mail.AuthenticationFailedException: AUTHENTICATE failed.
javax.mail.AuthenticationFailedException: AUTHENTICATE failed.
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 javax.mail.Service.connect(Service.java:121)
at TestSSL.main(TestSSL.java:66)
If I disable the PLAIN authentication (props.put("mail.imap.auth.plain.disable","true"); ) I get the following exception:
DEBUG: protocolConnect login, host=imap.test.local, user=test, password=<non-null>
java.lang.ClassNotFoundException: jcifs.ntlmssp.Type1Message
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.mail.auth.Ntlm.generateType1Msg(Ntlm.java:65)
at com.sun.mail.imap.protocol.IMAPProtocol.authntlm(IMAPProtocol.java:572)
at com.sun.mail.imap.IMAPStore.login(IMAPStore.java:667)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:596)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at javax.mail.Service.connect(Service.java:121)
at TestSSL.main(TestSSL.java:66)
IMAP DEBUG: Can't load NTLM authenticator
caught exception: javax.mail.MessagingException:
Can't load NTLM authenticator;
nested exception is:
com.sun.mail.iap.ProtocolException: Can't load NTLM authenticator
javax.mail.MessagingException: Can't load NTLM authenticator;
nested exception is:
com.sun.mail.iap.ProtocolException: Can't load NTLM authenticator
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:616)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at javax.mail.Service.connect(Service.java:121)
at TestSSL.main(TestSSL.java:66)
Caused by: com.sun.mail.iap.ProtocolException: Can't load NTLM authenticator
at com.sun.mail.imap.protocol.IMAPProtocol.authntlm(IMAPProtocol.java:577)
at com.sun.mail.imap.IMAPStore.login(IMAPStore.java:667)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:596)
... 4 more
I've been struggling with this the past couple of days with no luck. Manual authentication with the given credentials works. The password contains some special characters though: '%', '!', and '+'). Should I escape those somehow in JavaMail while authenticating? I tried constructing the username for the Exchange server in format "domain\username\email" without any luck. I tried setting up the store and properties to "imaps" without any luck. I also have the ssl handshake debug info where everything looks good until the authentication part...
Any ideas/suggestions are more than welcome!
Edited by: koshera on Jan 4, 2010 8:18 PM