I don't know if this is still relevant to you, but to everyone stumbling onto this question using Google; here's how to fix this:
Google deemed Apple's Mail client in (High) Sierra as "unsafe". If you have "restrict access by less safe applications" switched on in your GMail account, Apple Mail will not be able to login. The error as described in the question above will then appear.
The solution is to either 1) use a different mail client or 2) enable access in your Gmail account. Here's how:
- open https://myaccount.google.com/lesssecureapps in Safari and logon if requested
- flick the switch to the "on" position
- start Apple Mail and try to sync your GMail account (this should now work)
Hope this helps!
Kind regards,
Erwin.