2014-04-12 163 views
1

我正在使用JavaMail 1.5.1連接到多個電子郵件帳戶(不同的提供者等)。它看起來非常適合很多服務,但我遇到了嘗試連接到其中幾個問題的問題。兩者似乎都有相同的迴應。使用JavaMail連接到IMAP活動的Exchange服務器

給我麻煩的服務之一是由apptix.com提供的。正如我從他們online docs(第21頁)的讀取SMTP/IMAP設置如下:

  • SMTP主機:smtp.apptixemail.net
  • SMTP端口:587
  • TLS

  • IMAP主持人:imap.apptixemail.net

  • IMAP端口:993
  • SSL

我有我的測試用戶的用戶名和密碼。我可以連接到SMTP,但不能連接到IMAP。這裏是我的代碼連接到IMAP

public static IMAPStore connectToImap(String host, int port, String username, String password) throws MessagingException { 
    Properties props = System.getProperties(); 
    props.setProperty("mail.imap.sasl.enable", "true"); 
    props.setProperty("mail.imap.starttls.enable", "true"); 

    props.setProperty("mail.imap.auth.ntlm.disable", "true"); 
    props.setProperty("mail.imap.auth.plain.disable", "true"); 
    props.setProperty("mail.imap.auth.gssapi.disable", "true"); 
    props.setProperty("mail.imap.ssl.enable", "true"); 

    Session imapSession = Session.getInstance(props); 
    IMAPStore store = new IMAPStore(imapSession, null); 
    store.connect(host, port, username, password); 

    return store; 
} 

這裏是我在執行該方法後獲得跟蹤連接到SMTP和IMAP

DEBUG: setDebug: JavaMail version 1.5.1 
DEBUG SMTP: useEhlo true, useAuth false 
DEBUG SMTP: trying to connect to host "smtp.apptixemail.net", port 587, isSSL false 
220 smtp.apptixemail.net Microsoft ESMTP MAIL Service ready at Fri, 11 Apr 2014 19:50:15 -0500 
DEBUG SMTP: connected to host "smtp.apptixemail.net", port: 587 

EHLO 10.58.0.246 
250-smtp.apptixemail.net Hello [10.2.64.1] 
250-SIZE 57671680 
250-PIPELINING 
250-DSN 
250-ENHANCEDSTATUSCODES 
250-STARTTLS 
250-AUTH LOGIN 
250-8BITMIME 
250-BINARYMIME 
250 CHUNKING 
DEBUG SMTP: Found extension "SIZE", arg "57671680" 
DEBUG SMTP: Found extension "PIPELINING", arg "" 
DEBUG SMTP: Found extension "DSN", arg "" 
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg "" 
DEBUG SMTP: Found extension "STARTTLS", arg "" 
DEBUG SMTP: Found extension "AUTH", arg "LOGIN" 
DEBUG SMTP: Found extension "8BITMIME", arg "" 
DEBUG SMTP: Found extension "BINARYMIME", arg "" 
DEBUG SMTP: Found extension "CHUNKING", arg "" 
STARTTLS 
220 2.0.0 SMTP server ready 
EHLO 10.58.0.246 
250-smtp.apptixemail.net Hello [10.2.64.1] 
250-SIZE 57671680 
250-PIPELINING 
250-DSN 
250-ENHANCEDSTATUSCODES 
250-AUTH LOGIN 
250-8BITMIME 
250-BINARYMIME 
250 CHUNKING 
DEBUG SMTP: Found extension "SIZE", arg "57671680" 
DEBUG SMTP: Found extension "PIPELINING", arg "" 
DEBUG SMTP: Found extension "DSN", arg "" 
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg "" 
DEBUG SMTP: Found extension "AUTH", arg "LOGIN" 
DEBUG SMTP: Found extension "8BITMIME", arg "" 
DEBUG SMTP: Found extension "BINARYMIME", arg "" 
DEBUG SMTP: Found extension "CHUNKING", arg "" 
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM 
DEBUG SMTP: AUTH LOGIN command trace suppressed 
DEBUG SMTP: AUTH LOGIN succeeded 
DEBUG: setDebug: JavaMail version 1.5.1 
DEBUG IMAP: mail.imap.fetchsize: 16384 
DEBUG IMAP: mail.imap.ignorebodystructuresize: false 
DEBUG IMAP: mail.imap.statuscachetimeout: 1000 
DEBUG IMAP: mail.imap.appendbuffersize: -1 
DEBUG IMAP: mail.imap.minidletime: 10 
DEBUG IMAP: disable AUTH=PLAIN 
DEBUG IMAP: disable AUTH=NTLM 
DEBUG IMAP: enable STARTTLS 
DEBUG IMAP: enable SASL 
DEBUG IMAP: trying to connect to host "imap.apptixemail.net", port 993, isSSL true 
* OK The Microsoft Exchange IMAP4 service is ready. 
A0 CAPABILITY 
* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN CHILDREN IDLE NAMESPACE LITERAL+ 
A0 OK CAPABILITY completed. 
DEBUG IMAP: AUTH: NTLM 
DEBUG IMAP: AUTH: GSSAPI 
DEBUG IMAP: AUTH: PLAIN 
DEBUG IMAP: protocolConnect login, host=imap.apptixemail.net, [email protected], password=<non-null> 
DEBUG IMAP: SASL authentication command trace suppressed 
DEBUG IMAP: SASL Mechanisms: 
DEBUG IMAP: NTLM 
DEBUG IMAP: GSSAPI 
DEBUG IMAP: PLAIN 
DEBUG IMAP: 
2014-04-11 17:50:26.614 java[32026:1003] Unable to load realm info from SCDynamicStore 
DEBUG IMAP: Failed to create SASL client, THROW: 
javax.security.sasl.SaslException: Failure to initialize security context [Caused by GSSException: Invalid name provided (Mechanism level: Could not load configuration from SCDynamicStore)] 
    at com.sun.security.sasl.gsskerb.GssKrb5Client.<init>(GssKrb5Client.java:132) 
    at com.sun.security.sasl.gsskerb.FactoryImpl.createSaslClient(FactoryImpl.java:45) 
    at javax.security.sasl.Sasl.createSaslClient(Sasl.java:354) 
    at com.sun.mail.imap.protocol.IMAPSaslAuthenticator.authenticate(IMAPSaslAuthenticator.java:131) 
    at com.sun.mail.imap.protocol.IMAPProtocol.sasllogin(IMAPProtocol.java:765) 
    at com.sun.mail.imap.IMAPStore.login(IMAPStore.java:761) 
    at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:665) 
    at javax.mail.Service.connect(Service.java:345) 
    at test.Mailbox.connectToImap(MailboxUtils.java:561) 
    at test.TestUserPass.main(TestUserPass.java:470) 
Caused by: GSSException: Invalid name provided (Mechanism level: Could not load configuration from SCDynamicStore) 
    at sun.security.jgss.krb5.Krb5NameElement.getInstance(Krb5NameElement.java:110) 
    at sun.security.jgss.krb5.Krb5MechFactory.getNameElement(Krb5MechFactory.java:80) 
    at sun.security.jgss.GSSManagerImpl.getNameElement(GSSManagerImpl.java:188) 
    at sun.security.jgss.GSSNameImpl.getElement(GSSNameImpl.java:428) 
    at sun.security.jgss.GSSNameImpl.init(GSSNameImpl.java:157) 
    at sun.security.jgss.GSSNameImpl.<init>(GSSNameImpl.java:127) 
    at sun.security.jgss.GSSManagerImpl.createName(GSSManagerImpl.java:123) 
    at com.sun.security.sasl.gsskerb.GssKrb5Client.<init>(GssKrb5Client.java:90) 
    ... 9 more 
DEBUG IMAP: SASL authentication failed 
DEBUG IMAP: LOGIN command trace suppressed 
DEBUG IMAP: LOGIN command result: A1 NO LOGIN failed. 
Exception in thread "main" javax.mail.AuthenticationFailedException: LOGIN failed. 
    at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:684) 
    at javax.mail.Service.connect(Service.java:345) 
    at test.Mailbox.connectToImap(MailboxUtils.java:561) 
    at test.TestUserPass.main(TestUserPass.java:470) 

我不知道爲什麼是怎麼回事。我只是不知道爲什麼這不起作用。我不知道它是否與GSSAPI異常有關,或者與GSSAPI異常有關...如果您可以在代碼中選擇,我禁用了ntlm和plain(如JavaMail docs中所建議的),但沒有任何結果。

+0

你嘗試了 「KRB5」 Java系統屬性中提到[這裏](http://mail-archives.apache.org/mod_mbox/hadoop-common-user/201306.mbox/%[email protected]。 gmail.com%3E)? – vanOekel

+0

是的,我做到了。但說實話,我並不完全明白我需要在道具上放置什麼。 – plunchete

回答

1

我已經解決了這個問題,甚至不涉及代碼中的問題我想在這裏記錄它爲什麼失敗。

似乎我使用的IMAP主機(imap.apptix.com)僅適用於Outlook,但它不適用於JavaMail。我已經獲得了有關該服務的更多信息,並指出imap.collaborationhost.net作爲Thunderbird的IMAP主機。我已經在我的代碼中嘗試過它,並且它能夠工作。

此外,我想指出,GSSException只是一個警告,不會影響最終結果。我也通過成功的身份驗證來獲得它。

相關問題