Gmail smtp not able to send email javax.mail.AuthenticationFailedException:

November 17, 2019 401 views
Security Email DigitalOcean Java

I have set gmail for less secure app already Also set IMAP forwarding

Locally sending emails works but the problem occurs in

digital ocean droplet [without ssl or domain] via ip address

Email Setting using java simple mail

private EmailMailer(){
        setMailer(new Mailer(new ServerConfig("smtp.gmail.com", 587,EmailConstants.EMAIL_ID, EmailConstants.EMAIL_PASSWORD),
                TransportStrategy.SMTP_TLS));
    }

Checked Digital ocean was able to connect to port 587

Getting error while sending mail


Caused by: javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbuD
ww-app_1    | 534-5.7.14 ywow3CZ7TbpX5mHNs0LChqgXAsXoucspMfedy2oAIDqjP0MH4RO8M_1bLvhh6f3Ha0Fj_a
ww-app_1    | 534-5.7.14 RhfPx0WlDHIfsXUR8rbVLiSrSAr-hfc0PsOweMs0xMqQhHb6LhXMusyjtsfGzF> Please
ww-app_1    | 534-5.7.14 log in via your web browser and then try again.
ww-app_1    | 534-5.7.14  Learn more at
ww-app_1    | 534 5.7.14  https://support.google.com/mail/answer/78754 a6sm8956026qth.74 - gsmtp
ww-app_1    | 
ww-app_1    |   at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:914)
ww-app_1    |   at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:825)
ww-app_1    |   at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:730)
ww-app_1    |   at javax.mail.Service.connect(Service.java:388)
ww-app_1    |   at javax.mail.Service.connect(Service.java:246)
ww-app_1    |   at javax.mail.Service.connect(Service.java:195)
ww-app_1    |   at org.simplejavamail.mailer.internal.mailsender.MailSender.sendMailClosure(MailSender.java:252)
ww-app_1    |   ... 59 more
1 Answer

Hello, @cbondy

Can you confirm if you have 2 factor authentication enabled as well? I had a similar case and I’ve needed to turn less secure app ON test my code and and then turn it off again.

Have you tried doing so?

Regards,
Alex

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!