Since July 15 2014, Google have by default disabled access by "less secure apps" to things like IMAPS.
This means running something like mbsync or getmail which only uses PLAIN or LOGIN AUTH is declared a "less secure app" and will put you into a loop of being told to log into your account via a web page to confirm the login attempt was you, force doing a very secure confirmation that it IS you, and then just throw the same damn error again.