Getting SunCertPathBuilderException when sending mail from Java via SSL?

Do you get SunCertPathBuilderException: unable to find valid certification path to requested target when you try to send a mail from java via smtp(TLS and SSL)? There are 2 possible problems:

  • One option could be from the antivirus/firewall which prevent the communication for a specific port(default 465 for SSL and 587 for TSL) or for the java.exe. In the case you have a recent JDK/JRE and you use a well-known service this is probably the problem. Just try to disable the antivirus and to send again the mail from java. If it doesn’t work check the next point
  • You have an invalid/expired certificate for the email server so the SSL/TLS authentication doesn’t work properly. In order to overcome this you have to install the valid certificate.
  • Continue reading