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, [email protected], password=<non-null>
A1 LOGIN [email protected] 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, [email protected], password=<non-null>
A1 LOGIN [email protected] 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", "[email protected]");
imapProps.setProperty("password", "password");
String host = "host.domain.com";
int port = Integer.parseInt("993");
Authenticator authenticator = new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("[email protected]", "password");
}
};
session = Session.getInstance(imapProps, authenticator);
session.setDebug(true);
Store store = session.getStore("imaps");
store.connect(host, "[email protected]", "password");
As a Microsoft 365 admin for Enterprises, Midsize, or Education, you can also access EAC by selecting Admin > Exchange in the Microsoft Online Portal. In the EAC, navigate to Recipients > Mailboxes. In the list of mailboxes, select the mailbox that you want to assign permissions for, and then select Edit .
Within our app, go to Settings > Add Account > Add Email Account > Enter your email address and continue. If it does not automatically detect you are using an Exchange account, tap "not a ___ account" then tap the Exchange icon on the account setup page.
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.
It will workout if the username and the mail id both are same.
For example: system username is john and mail id [email protected]
IMAP is try to login the mail id using the username "john" from [email protected], if the user id is differ it will not login.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With