smtp - Java Why did my email session method stop working? -


this question has answer here:

i'm using class/method old project of mine send email programmatically. worked then, i'm getting errors elude kind of gmail security update since last used class in old project:i tried logging in , out through browser, didn't help.

the stack trace shows:

javax.mail.authenticationfailedexception: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=akgnsbs6 534-5.7.14 zjapothluigjlcm06bo2g599ldmo1v8iprezebe8fvdk3uj4kcgtg7cbeuzfjv1zrjkty8 534-5.7.14 tnv7ouzgzsblfq4n89fwfdcyss1fnsywlgldaewbfbltw9en5axc0_s_7g8kw0ehls7ido 534-5.7.14 mesq-fbs3ebd_f78qv3iopgesacqreh_42bz8xnouzbwfnp02pqlvqcv7wbf_-0ydtxlx4 534-5.7.14 dzb0an9hzcoogawn1j79heqgk4g9w> please log in via web browser , 534-5.7.14 try again. 534-5.7.14  learn more @ 534 5.7.14  https://support.google.com/mail/answer/78754 s59sm4398674qtd.20 - gsmtp  @ com.sun.mail.smtp.smtptransport$authenticator.authenticate(smtptransport.java:893) @ com.sun.mail.smtp.smtptransport.authenticate(smtptransport.java:814) @ com.sun.mail.smtp.smtptransport.protocolconnect(smtptransport.java:728) @ javax.mail.service.connect(service.java:364) @ javax.mail.service.connect(service.java:245) @ javax.mail.service.connect(service.java:265) @ javax.mail.transport.send0(transport.java:251) @ javax.mail.transport.send(transport.java:174) @ emailer.sendemail(notificationhandler.java:70)` . . . 

and here's code

class emailer  {     private static string host = "smtp.gmail.com";    private static string user = "myaccount@gmail.com";    private static string pass = "mypassword";     public static void sendemail(string fromaddr, string toaddr, string subject, string body) {        properties props = new properties();        props.put("mail.smtp.auth", "true");        props.put("mail.smtp.starttls.enable", "true");        props.put("mail.smtp.host", "smtp.gmail.com");        props.put("mail.smtp.port", "587");        session session = session.getinstance(props, null);         mimemessage message = new mimemessage(session);         try {            message.setfrom(new internetaddress(fromaddr));            message.setrecipients(message.recipienttype.to, internetaddress.parse(toaddr));            message.setsubject(subject);            message.settext(body);            transport.send(message, user, pass);        }         catch (addressexception e) {           e.printstacktrace();        }         catch (messagingexception e) {           e.printstacktrace();        } } 

possibly because google blocking email client.

google may block sign-in attempts apps or devices not use modern security standards. since these apps , devices easier break into, blocking them helps keep account safe.

i ran problem 2 months ago, java app cannot send emails testing gmail account. link explains in not detail. offer steps disable this.


Comments