Search code examples
androidemailgmailjakarta-mailimap

Invalid SASL argument in my Android application


Hi and sorry for my english. I try to get the number of unread messages from the first gmail account found it in an android phone, through javamail. This is my code:

//IMAPS protocol
    Properties props2 = new Properties();
    props2.setProperty("mail.store.protocol", "imaps");
    props2.setProperty("mail.imaps.host", "imaps.google.com");
    props2.setProperty("mail.imaps.port", "993");
    props2.setProperty("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    props2.setProperty("mail.imaps.socketFactory.fallback", "false");

    //Setting IMAP session
    Session imapSession = Session.getInstance(props2);

    try {

        store = imapSession.getStore("imaps");
        store.connect("imaps.google.com", account, pass);          

        inbox = store.getFolder("INBOX");
        inbox.open(Folder.READ_ONLY);

        return inbox.getUnreadMessageCount();

    } catch (Exception mex) {
        mex.printStackTrace();
        return 0;
    }

At moment to execute in my phone, logcat shows me that:

07-23 11:58:19.051: W/System.err(5430): javax.mail.MessagingException: A1 BAD Invalid SASL argument. ye3mb61911974vdc;

07-23 11:58:19.061: W/System.err(5430): nested exception is:

07-23 11:58:19.061: W/System.err(5430): com.sun.mail.iap.BadCommandException: A1 BAD Invalid SASL argument. ye3mb61911974vdc

I have no idea what may be going on, because if the password is bad shows me the corresponding authentication failure error, but if it is good shows me the error I posted above.


Solution

  • You should fix these common mistakes.

    There is no host "imaps.google.com" so I have no idea what you're really connecting to.

    Can you post the debug output showing the failure?

    What version of JavaMail are you using?

    Note that if you're using the current version of JavaMail, the debug output will NOT include the SASL exchange that will show the error, because that exchange will include your password. Conversely, if you're using an older version, be careful what you post because it might include an encoded version of your password.