I had encountered 5.1.1 Authentication error. Solution is to just change your gmail password to 16-character password with all variations(capitals, numbers, symbols).
This works because Gmail enforces 16-character password as App code for external gmail access. By custom creating the same, it is accepting it as App code.