1

I'm using JavaMail 1.5.1 to connect to several email accounts (different providers, etc). It looks perfect for lots of services but I've run into problems trying to connect to a couple of them. Both seems to have the same response.

One of the services that are giving me trouble is provided by apptix.com. As I've read from their online docs (page 21) the smtp/imap settings are the following:

  • smtp host: smtp.apptixemail.net
  • smtp port: 587
  • TLS

  • imap host: imap.apptixemail.net

  • imap port: 993
  • SSL

I've got the user and password for my test user. I'm able to connect to SMTP but not to IMAP. Here is my code to connect to 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;
}

And here is the trace that I'm getting after executing the method to connect to SMTP and 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)

I'm wondering why is going on. I just have no clue about why this is not working. I don't know if it has something to do with the GSSAPI exception or if it's something different ... As you can se in the code I've disabled ntlm and plain (as suggested in the JavaMail docs) but nothing.

2
  • Did you try the "krb5" Java system properties as mentioned here?
    – vanOekel
    Apr 12, 2014 at 13:01
  • Yes, I did. But to be completely honest I don't fully understand what I need to put in those props.
    – plunchete
    Apr 14, 2014 at 14:49

1 Answer 1

1

I've solved this and even that it doesn't involve a problem in code I would like to document here why it was failing.

Seems like the IMAP host that I was using (imap.apptix.com) was only for Outlook but it didn't work for JavaMail. I've got more information about the service and they point imap.collaborationhost.net as the IMAP host for Thunderbird. I've tried it in my code and boom it worked.

Also, I would like to point out that the GSSException was only a warning and not affecting the end result. I'm getting it with the successful authentication too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.