javax.mail.AuthenticationFailedException
If you are sending an email from Java program through Gmail SMTP, you may face the below exception in your stack trace while sending an email.
javax.mail.AuthenticationFailedException
exception generally caused by less secured applications/devices.
Exception in thread "main" java.lang.RuntimeException: javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbvU
534-5.7.14 jDcbiOHe-6qc4D3ml0EN96Nupa-5WHLuadRMSLYQp0ZNuqYXiJECfzYsW_amc7SCDv_gPD
534-5.7.14 VruxPXmN_yAo0EVTrzE96T1yoM9R6ObbJkllStea0fYtHuxJRn0076R3eLK4VAZk-g5MmJ
534-5.7.14 MLnuRZ7xa1-nfHgGkcgFS7hlQz7MWzvFuEH11ynl2Ggerr01L7jZQdSVPOqxDsRC4oAcsg
534-5.7.14 w9yPbVZegWP0ULG10kNy9eLItN3TE> Please log in via your web browser and
534-5.7.14 then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/answer/78754 c12sm7876642pfl.79 - gsmtp
at org.websparrow.SendEmail.main(SendEmail.java:52)
Caused by: javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbvU
534-5.7.14 jDcbiOHe-6qc4D3ml0EN96Nupa-5WHLuadRMSLYQp0ZNuqYXiJECfzYsW_amc7SCDv_gPD
534-5.7.14 VruxPXmN_yAo0EVTrzE96T1yoM9R6ObbJkllStea0fYtHuxJRn0076R3eLK4VAZk-g5MmJ
534-5.7.14 MLnuRZ7xa1-nfHgGkcgFS7hlQz7MWzvFuEH11ynl2Ggerr01L7jZQdSVPOqxDsRC4oAcsg
534-5.7.14 w9yPbVZegWP0ULG10kNy9eLItN3TE> Please log in via your web browser and
534-5.7.14 then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/answer/78754 c12sm7876642pfl.79 - gsmtp
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:826)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:761)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:685)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at org.websparrow.SendEmail.main(SendEmail.java:46)
Solution
Step 1: Login to your Gmail account and hit this https://www.google.com/settings/security/lesssecureapps
Step 2: If Allow less secure apps: is OFF, click the radio button and make it ON.
Step 3: Now try to send again. Hope this will help you. Thank You!