java - javax.mail.MessagingException while sending mail using JavaMail API -


i trying send email using javamail api, through gmail account, getting javax.mail.messagingexception exception

the code :

  public static result sendmail() {        map < string, string[] > values = request().body().asformurlencoded();        string toaddresses = values.get("toaddrs")[0];       string subject = values.get("subject")[0];       string body = values.get("body")[0];        properties props = new properties();       props.put("mail.smtp.host", "smtp.gmail.com");       props.put("mail.smtp.socketfactory.port", "465");       props.put("mail.smtp.socketfactory.class", "javax.net.ssl.sslsocketfactory");       props.put("mail.smtp.auth", "true");       props.put("mail.smtp.port", "465");        session session = session.getdefaultinstance(props, new javax.mail.authenticator() {           protected passwordauthentication getpasswordauthentication() {               return new passwordauthentication("samplemail@gmail.com", "samplepass");           }       });        try {            message message = new mimemessage(session);           message.setfrom(new internetaddress("samplemail@gmail.com"));           message.setrecipients(message.recipienttype.to, internetaddress.parse(toaddresses));           message.setsubject(subject);           message.settext(body);            transport.send(message);           return ok("sent");        } catch (messagingexception e) {           return ok("error in sending email");       }     } 

on debugging, end here in service classs service class

which throws exception : javax.mail.messagingexception: host, username, , password must specified.

correct these common mistakes. if still doesn't work, post debug output.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -