3

I am trying to connect to gmail using SMACK API but getting the below error and I am stuck with this past 2 days.

Exception in thread "main" org.jivesoftware.smack.sasl.SASLErrorException: SASLError using PLAIN: not-authorized
at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:348)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.login(XMPPTCPConnection.java:244)
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:442)

I am using smack 4.0.3 jars and Java 7. gmail is not blocked in my office network. I have tired all the suggestion given in the forums.

1. setting SASLMechanism to PLAIN / DIGEST-MD5.   
2. adding the Thread.sleep delay after connect.  
3. by setting the dummy SSLSocketFactory. 
4. removing the domain name from user name. 

Below is code which I am trying to execute.

public class JabberExample {
public static void main(String[] args) throws Exception{

    XMPPTCPConnection con = new XMPPTCPConnection("gmail.com");
    SASLAuthentication.supportSASLMechanism("PLAIN",0);

    con.connect();
    con.login("username", "password");

    Chat chat = ChatManager.getInstanceFor(con).createChat("chatusernam@gmail.com", new MessageListener() {
         public void processMessage(Chat chat, Message message) {
             System.out.println("Received message: " + message);
         }
     });

    chat.sendMessage("Message..!!");

     con.disconnect();
}

}

I hope i get some suggestions and help here.

Flow
  • 23,572
  • 15
  • 99
  • 156
Bhanu
  • 31
  • 1
  • 3

1 Answers1

10

Google has recently switched to not allowing PLAIN and similar methods on its accounts - https://support.google.com/accounts/answer/6010255.

If you want to use such auth mechanisms, the account will need to enable them - https://www.google.com/settings/security/lesssecureapps

Kev
  • 2,234
  • 1
  • 12
  • 6
  • Kev,thank for help. after enabling auth mechanism I am able to connect to Gmail and chat successfully. – Bhanu Sep 02 '14 at 11:53
  • 2
    You're welcome. If this is resolved, might you consider accepting the answer please, so others can find it? – Kev Sep 02 '14 at 12:12