I am using a java program to connect to a mailbox and read Emails from a folder in the mailbox. I am using Java Mail 1.5.6
and Java 8. Below is my code for connecting:
IMAPSSLStore returnImapConnectStore() throws InvalidKeyException,
NoSuchAlgorithmException, NoSuchPaddingException,
IllegalBlockSizeException, BadPaddingException,
AuthenticationFailedException, IllegalStateException {
IMAPSSLStore store = null;
Properties props = System.getProperties();
props.setProperty("mail.imaps.starttls.enable", "true");
props.setProperty("mail.imaps.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.imaps.auth.ntlm.disable", "true");
props.setProperty("mail.imaps.auth.plain.disable", "true");
props.setProperty("mail.imaps.auth.gssapi.disable", "true");
props.setProperty("mail.imaps.ssl.enable", "true");
String host = "imapmail.company.com";
final String username = "username";
final String password = "password"
try {
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username,
password);
}
});
session.setDebug(true);
store = new IMAPSSLStore(session, null);
store.connect(host, 993, username, password);
} catch (Exception e) {
System.err.println("Connection to server error.....");
e.printStackTrace();
}
return (store);
}
The program worked fine until there was a change in the password for the username
. When I updated the password and ran the program, I get the following error:
DEBUG: setDebug: JavaMail version 1.5.6
DEBUG IMAPS: mail.imap.fetchsize: 16384
DEBUG IMAPS: mail.imap.ignorebodystructuresize: false
DEBUG IMAPS: mail.imap.statuscachetimeout: 1000
DEBUG IMAPS: mail.imap.appendbuffersize: -1
DEBUG IMAPS: mail.imap.minidletime: 10
DEBUG IMAPS: enable STARTTLS
DEBUG IMAPS: closeFoldersOnStoreFailure
DEBUG IMAPS: trying to connect to host "imapmail.company.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 IMAPS: AUTH: NTLM
DEBUG IMAPS: AUTH: GSSAPI
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: protocolConnect login, host=imapmail.company.com, user=username, password=<non-null>
DEBUG IMAPS: mechanism PLAIN disabled by property: mail.imaps.auth.plain.disable
DEBUG IMAPS: mechanism LOGIN not supported by server
DEBUG IMAPS: mechanism NTLM disabled by property: mail.imaps.auth.ntlm.disable
DEBUG IMAPS: mechanism XOAUTH2 disabled by property: mail.imaps.auth.xoauth2.disable
DEBUG IMAPS: LOGIN command trace suppressed
DEBUG IMAPS: LOGIN command result: A1 NO Server Unavailable. 15
DEBUG IMAPS: trying to connect to host "imapmail.company.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 IMAPS: AUTH: NTLM
DEBUG IMAPS: AUTH: GSSAPI
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: protocolConnect login, host=imapmail.company.com, user=username, password=<non-null>
DEBUG IMAPS: mechanism PLAIN disabled by property: mail.imaps.auth.plain.disable
DEBUG IMAPS: mechanism LOGIN not supported by server
DEBUG IMAPS: mechanism NTLM disabled by property: mail.imaps.auth.ntlm.disable
DEBUG IMAPS: mechanism XOAUTH2 disabled by property: mail.imaps.auth.xoauth2.disable
DEBUG IMAPS: LOGIN command trace suppressed
DEBUG IMAPS: LOGIN command result: A1 NO Server Unavailable. 15
Connection to server error.....
javax.mail.AuthenticationFailedException: Server Unavailable. 15
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:725)
at javax.mail.Service.connect(Service.java:388)
I tried using the old password again and it gives me :
DEBUG IMAPS: LOGIN command result: A1 NO LOGIN failed.
Connection to server error.....
javax.mail.AuthenticationFailedException: LOGIN failed.
I am not sure how I should solve this error. I searched online but didn't find any useful resources for my problem.
Any help would be appreciated. Thank you!