• Register
0 votes
273 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?

6 5 3
6,930 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

9 7 4
38,600 points

Related questions

0 votes
1 answer 305 views
305 views
Problem : I am trying to call an SSL protected web service running on JDK7 based client, but getting bellow error javax.net.ssl.sslexception received fatal alert unexpected_message
asked Nov 5, 2019 peterlaw 6.9k points
0 votes
2 answers 342 views
342 views
Problem : Has anyone faced this error before? I am new to SSL javax.net.ssl.sslexception: received fatal alert: protocol_version
asked Nov 2, 2019 peterlaw 6.9k points
0 votes
3 answers 201 views
201 views
Problem : I am trying to setup a SSL Socket connection. But i am getting below error javax.net.ssl.sslhandshakeexception received fatal alert bad_certificate
asked Oct 23, 2019 peterlaw 6.9k points
0 votes
1 answer 22 views
22 views
Problem: I am trying to consume a PHP webservice which has the SSL certificate. I have the .net 3.5 Class library it references the webservice with a 'Add Service references' in Visualstudio 2010 If I try calling the main method of my webservice then I ... SslPolicyErrors sslPolicyErrors) { return true; } But somehow it is not working. Also I have already a certificate installed on my own pc.
asked Aug 12 Raphael Pacheco 4.9k points