Java mail by SSL
如果没有设置证书,会出现以下Exception:
1
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
要解决这个问题,方法有两个:
- java的启动参数添加 -Djavax.net.ssl.trustStore=/path/to/jssecacerts
- Add properties in java code
1
2
3Properties systemProps = System.getProperties();
systemProps.put( "javax.net.ssl.trustStore", "/path/to/jssecerts");
System.setProperties(systemProps);
参考:
http://www.rap.ucar.edu/staff/paddy/cacerts/index.html
http://code.google.com/p/java-use-examples/source/browse/trunk/src/com/aw/ad/util/InstallCert.java