关于用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, 下载次数: 105)
2011-06-22 09:33 上传
下载次数: 105
sendmail

根据提示信息查看邮件发送情况


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值