I am still flustered by this problem, and none of my answers are a sufficient solution 😟 Sorry about that.
In order to further debug the problem, and remove interference of 9 years of bread-crumbs in my keychain, I started by removing the Google account on my MBP using the "Internet Accounts" dialog. I then proceeded to open the keychains app, and query for all keys involving gmail.com, and remove all keychain entries, local and iCloud, that linked to gmail.com - but not those that were Safari passwords merely using my gmail address as user key. Be very careful, if you try that yourself! I even checked Mail that there were no more Gmail SMTP servers, which have a tendency to hang on even if you remove your Google account.
After that, I proceeded to set up my Google account again. All my iDevices also suddenly wanted me to set up my Gmail account again, too. The remaining problem is as follows: Once I connect to a new network, and start Mail, it cannot synch with Gmail. I often have a similar problem on my iDevices, too. On the MBP I see the following hints in my log file:
2015-05-29 08:22:39.532 sandboxd[290] ([2339]) Mail(2339) deny mach-lookup com.apple.GSSCred
2015-05-29 08:22:39.567 Mail[2339] Stream 0x600000307980 is sending an event before being opened
2015-05-29 08:22:40.228 Mail[2339] {"status":"400","schemes":"Bearer","scope":"https://mail.google.com/"}
2015-05-29 08:22:40.976 Mail[2339] Stream 0x6000001174f0 is sending an event before being opened
2015-05-29 08:22:41.093 Mail[2339] Stream 0x60800011a820 is sending an event before being opened
2015-05-29 08:22:41.221 Mail[2339] XOAUTH2 requires user
2015-05-29 08:22:41.221 Mail[2339] Failed to start the SASL connection SASL(-1): generic failure: XOAUTH2 requires user
2015-05-29 08:22:44.708 accountsd[277] Enter ShareKitAccountEnabler - didChangeWithType - type=2 for account XXX@XXX.com (A57DA091-ACFB-472B-8ED0-465958D06739).
2015-05-29 08:22:44.709 accountsd[277] AIDA Notification plugin running
2015-05-29 08:22:44.920 icbaccountsd[2344] Connection error while checking Apple Internalness. Error: Error Domain=NSCocoaErrorDomain Code=4099 "Couldn’t communicate with a helper application." (The connection to service named com.apple.CrashReporterSupportHelper was invalidated.) UserInfo=0x7fd0db439ed0 {NSDebugDescription=The connection to service named com.apple.CrashReporterSupportHelper was invalidated.}
2015-05-29 08:22:44.982 sandboxd[290] ([2344]) icbaccountsd(2344) deny mach-lookup com.apple.CrashReporterSupportHelper
2015-05-29 08:22:45.021 Mail[2339] Stream 0x61000011aee0 is sending an event before being opened
2015-05-29 08:22:46.669 Mail[2339] No worthy mechs found
2015-05-29 08:22:46.669 Mail[2339] No worthy mechs found
2015-05-29 08:22:48.233 accountsd[277] Enter ShareKitAccountEnabler - didChangeWithType - type=2 for account YYY@gmail.com (DCBD516E-8254-4C6A-AE82-8405EAE0157A).
2015-05-29 08:22:48.233 accountsd[277] AIDA Notification plugin running
... [repeats] ...
2015-05-29 08:22:53.159 icbaccountsd[2344] SOSCCThisDeviceIsInCircle SOSCCThisDeviceIsInCircle!! 7
2015-05-29 08:22:53.372 icbaccountsd[2344] SOSCCThisDeviceIsInCircle SOSCCThisDeviceIsInCircle!! 8
... [interspersed, repeats] ...
where the icbaccountsd message repeats with an increasing number after it. Checking in Mail, there is a user name associated with both, the IMAP and the SMTP account. The "user" that the error message refers to might be something like the consumer key or access token of OAUTH. I'd also like to know, why the sandboxd denies the credential lookup to Mail.
My solution my current quandary is to quit Mail right there, and wait until the dot under the icon went away. Then, after reinvoking Mail, it will then connect with Gmail, no problems. Unfortunately, that does not help when my iDevices hang checking Gmail.
I would blame icloud keychain sharing, but it is too convenient a feature (when it work) to turn it off.