This discussion is archived
1 Reply Latest reply: Jul 4, 2013 10:16 AM by 247a4a0c-be75-4be5-b22a-11666780c07e RSS

GmailSSLStore doesn't work if password is empty

247a4a0c-be75-4be5-b22a-11666780c07e Newbie
Currently Being Moderated

I'm trying to use GmailSSLStore instead of IMAPSSLStore but when I try to connect using XOAUTH2 it throws the following exception:

Exception in thread "main" javax.mail.AuthenticationFailedException: Empty username or password. wj5if3658973pab.41

 

I've seen that this is something that happened before with IMAPSSLStore Empty password no longer accepted in 1.4.6 - needed for XOAUTH2 Gmail

 

I'm using the implementation that Google provides https://code.google.com/p/google-mail-oauth2-tools/source/browse/trunk/java/com/google/code/samples/oauth2/OAuth2Authent… but substituting the IMAPSSLStore with GmailSSLStore. Am I doing something wrong?

 

Edit: I've tried with javamail 1.4.7 and 1.5.0


Thanks,

Ignacio

  • 1. Re: GmailSSLStore doesn't work if password is empty
    247a4a0c-be75-4be5-b22a-11666780c07e Newbie
    Currently Being Moderated

    I've found my error. I was adding the following properties to the session:

     

        props.put("mail.imaps.sasl.enable", "true");

        props.put("mail.imaps.sasl.mechanisms", "XOAUTH2");

     

    When actually I needed:

     

          props.put("mail.gimaps.sasl.enable", "true");

          props.put("mail.gimaps.sasl.mechanisms", "XOAUTH2");


    The method looks like:


      public static GmailStore connectToImap(String host, int port, String userEmail, String oauthToken, boolean debug) throws Exception {

        

          Properties props = new Properties();

          props.put("mail.store.protocol", "gimaps");

          props.put("mail.gimaps.sasl.enable", "true");

          props.put("mail.gimaps.sasl.mechanisms", "XOAUTH2");

          props.put(OAuth2SaslClientFactory.OAUTH_TOKEN_PROP, oauthToken);

          Session session = Session.getDefaultInstance(props, null);

          final String emptyPassword = "";

          GmailStore store = (GmailStore) session.getStore("gimaps");

          store.connect(host, port, userEmail, emptyPassword);

          return store;

      }

     

    NOTE: Because Gmail always uses SSL GmailSSLStore is not needed, GmailStore does the same thing

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points