Die Verwendung von Javamail für den Zugriff auf Microsoft Exchange-Postfächer (IMAP, MS Exchange)

Ich muss eine Verbindung zu einem Microsoft Exchange-Server über IMAPS JavaMail. Zuerst bekam ich das:

A1 NO AUTHENTICATE failed.
javax.mail.AuthenticationFailedException: AUTHENTICATE failed.

Ausnahme in meinen debugger.

Dann deaktivierte ich einige Authentifizierung Protokolle:

imapProps.setProperty("mail.imaps.auth.plain.disable", "true");
imapProps.setProperty("mail.imaps.auth.ntlm.disable", "true");
imapProps.setProperty("mail.imaps.auth.gssapi.disable", "true");

Dies ist die neue Ausnahme, die ich bekommen hab (ich angehängt habe den ganzen 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, user=user@domain.com,  password=<non-null>
A1 LOGIN user@domain.com 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, user=user@domain.com, password=<non-null>
A1 LOGIN user@domain.com 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)

Jetzt bin ich immer "NO LOGIN failed" Ausnahme.

Dies ist mein vollständiger 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");
Dein code ist absolut korrekt (vielleicht einige Linien überhaupt nicht notwendig - authenticator Beispiel, weil Sie Benutzername und Kennwort in der connect - aber keine Sorge) es funktioniert innerhalb unserer exchange-Umgebung. Yo müssen, sprechen Sie mit Ihrem Exchange-SysAdmin-da sollte das problem von dieser Seite.
Sorry für das späte update. Ja, dieser code war richtig. Das Problem war mit dem Exchange-Server. Dieser code ist korrekt, wenn jemand plant, es zu benutzen..
Kannst du bitte beschreiben Sie das Problem, dass der Exchange-Server war, wenn Sie diesen Fehler erhalten. Danke!
Es war einfach, ich wurde mit den falschen Anmeldeinformationen. @ClickerTweeker

InformationsquelleAutor Dilanga Thalpegama | 2013-11-19

Schreibe einen Kommentar