关于用javamail发送邮件时,由于邮件服务器要SSL

发送邮件时得到异常如下:



exception reading response: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target





Google一下,需要保存安装证书



官方的QA  http://java.sun.com/products/javamail/FAQ.html#installcert



Q: When connecting to my mail server over SSL I get an exception like "unable to find valid certification path to requested target".
A: Your server is probably using a test certificate or self-signed certificate instead of a certificate signed by a commercial Certificate Authority. You'll need to install the server's certificate into your trust store. The InstallCert program will help.



在这里  http://blogs.sun.com/andreas/entry/no_more_unable_to_find  有解决方案



用  http://blogs.sun.com/andreas/resource/InstallCert.java  的代码来安装证书



1.编译安装证书程序 javac InstallCert.java;

   运行安装证书生成证书       java InstallCert smtp.mailtest.com:465
2.将得到jssecacerts文件后复制到jdk1.6.0_16\jre\lib\security或jre1.6.0_06\lib\security\目录

3.编译测试程序 javac -cp ./mail.jar;./ SendMail.java



4.运行java -cp ./mail.jar;./ SendMail


  SendMail.rar (293.93 KB, 下载次数: 62) 
根据提示信息查看邮件发送情况



注。smtp.mailtest.com 为测试的域名。根据实际情况修改测试程序及相关域名。


原文:http://bbs.chinaunix.net/thread-3555444-1-1.html

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐