我正在使用 java 程序连接到邮箱并从邮箱中的文件夹中读取电子邮件。我正在使用Java Mail 1.5.6
Java 8。下面是我的连接代码:
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);
}
该程序运行良好,直到username
. 当我更新密码并运行程序时,出现以下错误:
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)
我再次尝试使用旧密码,它给了我:
DEBUG IMAPS: LOGIN command result: A1 NO LOGIN failed.
Connection to server error.....
javax.mail.AuthenticationFailedException: LOGIN failed.
我不确定我应该如何解决这个错误。我在网上搜索,但没有找到任何有用的资源来解决我的问题。
任何帮助,将不胜感激。谢谢!