Saturday, December 2, 2017

JavaMail Could not connect to SMTP host SSL 465: handshake_failure

Ans:
SSLHandshakeException is a subclass of the IOException, so you do not need to catch is explicitly. Most developers will not need an explicit catch, but it may help you more easily diagnose the cause of any IOException.
When applying the -Djavax.net.debug=all property, the failure associated with this SSLHandshakeException would appear immediately after algorithm negotiation in the logs.
So, System.setProperty("javax.net.debug", "all"); is making error in your code.
What is the root cause of occuring SSLHandshakeException? How to prevent it?
Ans:
The most likely cause for SSLHandshakeException is algorithm support. The JDK provides a separate package called JCE Unlimited Strength, designed to add stronger algorithm support than what’s available by default. Qualys SSL Labs provides a different server SSL test that will enumerate which algorithms a server supports.
Adding stronger algorithms: JCE Unlimited Strength
In a high security environment, one way of strengthening algorithms in the JDK is through the JCE Unlimited Strength policy files. In this particular case, replacing those policy files within JDK 7 allows it to use the stronger variants of existing algorithms and connect successfully.
JCE Unlimited Strength downloads: JDK 8JDK 7, or JDK 6.

Resource Link:

  1. Diagnosing TLS, SSL, and HTTPS

You can try with it
you need to set certificate, to access the SMTP port.
System.setProperty("javax.net.ssl.trustStore","key");
System.setProperty("javax.net.ssl.trustStorePassword","password");
for generating a KeyStore and TrustStore, follow the tutorial

From Marvin Pinto's answer,
The javax.net.ssl.SSLHandshakeException exception is usually thrown when the server you're trying to connect to does not have a valid certificate from an authorized CA.
Put simply, the server you're attempting to connect to is most likely using a self-signed certificate and you have to accomodate for that in your Java code. This involves creating a custom KeyStore, etc. See this Stack Overflow answer for full implementation details.
If you want to clarify your conception completely, then read the tutorial which is for use of SSL with JavaMail.
Related Link:
  1. JAVAMAIL API FAQ
  2. Received fatal alert: handshake_failure through SSLHandshakeException

No comments:

Post a Comment