Using a desktop email client with Gmail should be fairly straight forward; generally it is. But sometimes it's the devil.
First make sure you've checked out the various 'how to configure for Gmail' pages around the net. Like this one from Lifehacker. Or this one from Google themselves. Make sure you're trying to configure properly for IMAP or POP depending on your needs.
Problem is I went through all these settings, 3 or 4 times each with all various options and still could not get things to work. In my case I was using Thunderbird ( I also tried Postbox with the same results).
With each I kept ending up with this sort of message.
The first 42 times I tried this over the course of a couple of weeks there was no further indication of what the problem might be. I was using the exact same credentials to access Gmail on the Gmail website, via Mac Mail, and on my iDevices.
A couple of weeks later I decided to take another stab at it. I really need the desktop client to help me coordinate the multiple email addresses that we use as a family. Yes I known I can log in and out of the web client, but I need something smoother, that allows me to view multiple accounts at the same time, like Mac Mail.
This time after I got the same failure message, I also recieved an email from Google telling me that 'someone had tried to login...... ' etc. etc. But it also had this part about using a 'less secure' app to access Gmail. I wouldn't have considered Thunderbird to be 'less secure', but maybe.
I followed the 'less secure' link and found a simple enable/disable setting. Sure enough, flipping the setting to 'Access for less secure apps: Enable' allowed the client to work with no problem.
Now I, like Google, wouldn't recommend leaving access for less secure apps enabled. So for now, I've flipped it back and am looking further into what exactly it is that has Gmail thinking clients like Postbox and Thunderbird are evil but Mac Mail isn't.
If you're using 2-Step authentication (well worth it), you can generate an app specific password for the mail client your using. This overrides whatever issue it is that Gmail has with the less secure apps, since it can only be used by that specific app. I was trying to avoid this as I have enough passwords to manage already. Remember, you can not generate app specific passwords unless you have 2 step authentication enabled.
Hopefully you'll come out the other side of this with your desktop email client working, or at least a plan to get it to work!