I ran into similar problems when trying to use Google's SMTP with python (specifically, when using Django). Here were the steps I used to fix the issue (some of them are "well known" and reported in many places, others aren't).
I personally use TSL + port 587. However, SSL + port 465 is also
valid (which you have).
Ensure you have the appropriate security settings in gmail. Some of
these may not be necessary, but it's what I had to set.
Settings > Forwarding and POP/IMAP > Enable IMAP Access. Settings >
Accounts and Import > Change account settings: > Other Google
Account Settings > Sign-in & Security > Connected apps & sites >
Allow less secure apps (enabled / on).
Finally (and this is the step that made my system work), reset your password.
For whatever reason, I kept getting errors from gmail prompting me to ensure my login was correct / login via browser, despite being absolutely sure the login info was correct (and being able to login with those credentials via browser). However, as soon as I changed the password and tried again, it "magically" worked.
This might just be a security feature gmail has in place where if you've tried to access the gmail via an app before privileges were enabled, then it will block access from unknown apps (or at least that app) until they truly "verify" it's you. But, that's just a guess...