email - javax.mail.AuthenticationFailedException Java Mail -


i have made little program send message email account. of code seems work fine. however, have encounter authenticationfailedexception when code hit transport.send in program. not sure why because think have set correctly. here code.

javaemail.java

public static void main (string[] args) throws exception{                 //intialize logger  protected static logger logger = logmanager.getlogger(javaemail.class.getname());  //smtp related parameters  private static string smtpuseremail; private static string smtpreceiveremailaddress; private static string smtpuserpassword; private static string smtpportnumber; private static string smtphost;  private static string emailsubject;  //stack error message variable  private static string message;          try {              logger.info("-----------------------------");             logger.info("---------starting up---------");             logger.info("-----------------------------");              initialize();              string body = "this test";              logger.info("start connect email server");              sendfromgmail(smtpuseremail, smtpuserpassword, smtpreceiveremailaddress, emailsubject, body);               // system.out.println("error message: " + message);              logger.info("email sent");           }         catch (exception e){             logger.error(e);              // message = e.tostring();              throw e;           }     }      //setting email server     private static void sendfromgmail(string from, string pass, string to, string subject, string body) {           properties props = propertiesutil.loadproperties("main.properties");          props.put("mail.smtp.auth", "true");         props.put("mail.smtp.starttls.enable", "true");         props.put("mail.smtp.host", smtphost);         props.put("mail.smtp.port", smtpportnumber);          session session = session.getinstance(props,                   new javax.mail.authenticator() {                     protected passwordauthentication getpasswordauthentication() {                         return new passwordauthentication(smtpuseremail, smtpuserpassword);                     }                   });          mimemessage message = new mimemessage(session);            try{               message.setfrom(new internetaddress(from));              message.addrecipient(message.recipienttype.to, new internetaddress(to));               message.setsubject(subject);              message.settext(body);              transport.send(message);              logger.info("message has been delievered, check mail");          }          catch (messagingexception e) {             logger.error("messaging exception");              throw new runtimeexception(e);         }     }       //initializing properties     private static void initialize() throws exception  {          properties props = propertiesutil.loadproperties("main.properties");          //smtp set         smtpportnumber = props.getproperty("portnumber");         smtpreceiveremailaddress = props.getproperty("recipientemailaddress");         smtpuseremail = props.getproperty("useremailaddress");         smtpuserpassword = props.getproperty("userpassword");         smtphost = props.getproperty("emailhost");         emailsubject = props.getproperty("");      }  } 

main.properties

portnumber = 465 recipientemailaddress = my@gmail.com userpassword = secert useremailaddress = my@gmail.com emailhost = smtp.gmail.com 

error

exception in thread "main" java.lang.runtimeexception: javax.mail.authenticationfailedexception: 534-5.7.14 <https://accounts.google.com/continuesignin?sarp=1&scc=1&plt=akgnsbvwe     534-5.7.14 hiw4hbxefm-ji-wxqek6ru2ljstc10iedxvhu_tzbft1iqpfsot0wfjawkrx2-glieg0nz     534-5.7.14 v45kwaeagzwtb_v1nae-bozsr6yzphq7-cyvgyplvcaexmfzil3imrgkcalmn-5fjrerkm     534-5.7.14 pjtrpd9nmjcosx0ce4dxsgn_y-qgosw-ehop2u3eqksreobxi-a80ywnwiy3quiv56f61h     534-5.7.14 yz8bmlpugqiyhh7dind6hpwvnhao> 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 ob15sm12759947pdb.52 - gsmtp          @ emailnotification.javaemail.sendfromgmail(javaemail.java:140)         @ emailnotification.javaemail.main(javaemail.java:63)     caused by: javax.mail.authenticationfailedexception: 534-5.7.14 <https://accounts.google.com/continuesignin?sarp=1&scc=1&plt=akgnsbvwe     534-5.7.14 hiw4hbxefm-ji-wxqek6ru2ljstc10iedxvhu_tzbft1iqpfsot0wfjawkrx2-glieg0nz     534-5.7.14 v45kwaeagzwtb_v1nae-bozsr6yzphq7-cyvgyplvcaexmfzil3imrgkcalmn-5fjrerkm     534-5.7.14 pjtrpd9nmjcosx0ce4dxsgn_y-qgosw-ehop2u3eqksreobxi-a80ywnwiy3quiv56f61h     534-5.7.14 yz8bmlpugqiyhh7dind6hpwvnhao> 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 ob15sm12759947pdb.52 - gsmtp          @ com.sun.mail.smtp.smtptransport$authenticator.authenticate(smtptransport.java:809)         @ com.sun.mail.smtp.smtptransport.authenticate(smtptransport.java:752)         @ com.sun.mail.smtp.smtptransport.protocolconnect(smtptransport.java:669)         @ javax.mail.service.connect(service.java:317)         @ javax.mail.service.connect(service.java:176)         @ javax.mail.service.connect(service.java:125)         @ javax.mail.transport.send0(transport.java:194)         @ javax.mail.transport.send(transport.java:124)         @ emailnotification.javaemail.sendfromgmail(javaemail.java:130)         ... 1 more 

go browser login gmail account trying in code, go link https://www.google.com/settings/security/lesssecureapps

you see

enter image description here

you should click turn on .


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -