六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 64|回复: 0

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

[复制链接]

升级  12%

16

主题

16

主题

16

主题

秀才

Rank: 2

积分
68
 楼主| 发表于 2013-2-3 13:34:03 | 显示全部楼层 |阅读模式
关于用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
 
根据提示信息查看邮件发送情况
 
注。smtp.mailtest.com 为测试的域名。根据实际情况修改测试程序及相关域名。
 
 
 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表