• Register
Log In
0 votes

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.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: 


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"));




catch (MessagingException e) 



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:


36.1k points
edited by

Related questions

0 votes
1 answer 129 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 237 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 131 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 38 views
Problem : I have the Java web service client, which consumes the web service via HTTPS. When I try to connect to the service URL (https://AAA.BBB.CCC.DDD:9443/ISomeService ), I get the exception as below: “ Java.security.cert.CertificateException: No subject alternative names present.”
asked Jan 21 jwilliam 3.9k points
0 votes
1 answer 88 views
Problem : I have a Java web service client, which consumes a web service via HTTPS. When I connect to the service URL, I get the exception java.security.cert.CertificateException: No subject alternative names present.
asked Oct 22, 2019 peterlaw 6.9k points