• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes
11 views

Problem :

I have a java complied package and it is sopposed to communicate with https server on net. But when i try running the compilation gives the following exception:

javax.net.ssl.sslexception: unrecognized ssl message, plaintext connection?

by (6.9k points)  

1 Answer

0 votes

Solution :

I had the similar issue but its working for me now, I have changed the setting of my google account by running bellow code: 

System.out.println("Start"); 

final String username = "myemail@gmail.com"; 

final String password = "************"; 

Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "465"); props.put("mail.transport.protocol", "smtp"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); 

Session session = Session.getInstance(props, new javax.mail.Authenticator() 

protected PasswordAuthentication getPasswordAuthentication()

 { 

return new PasswordAuthentication(username, password); 

}

); 

try { 

Transport transport=session.getTransport(); 

Message message = new MimeMessage(session); message.setFrom(new InternetAddress("myemail@gmail.com"));

//formBean.getString("fromEmail") message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("myemail@gmail.com")); message.setSubject("subject");

//formBean.getString( message.setText("mailBody"); transport.connect(); transport.send(message, InternetAddress.parse("myemail@gmail.com"));

//(message); 

System.out.println("Done");

 } 

catch (MessagingException e) 

System.out.println("e="+e); 

e.printStackTrace(); 

throw new RuntimeException(e); 

}

  • Disable the 2-step verification (password and OTP)

  • Enabling to allow to access less secure app(Allow less secure apps: ON.)

Now you will be able to send mail using above program.

Further Readings:

https://github.com/nctoolbox/nctoolbox/issues/94

by (21.9k points)  
edited by
...