javax.mail.AuthenticationFailedException is thrown while sending email in java

I had the same problem! Google prevents access for less secure apps.

This is how I solved it:

  • Log in from your browser to that email account.
  • Go to https://www.google.com/settings/security/lesssecureapps
  • You will see Turn off or Turn on. Click on Turn on, then try your code again. It should work now.

Leave a Comment