javamail 关于SSL的问题找了我一个星期之久

关于javamail 使用SSl方式发送邮件的问题。我在官网上面终于找到答案了。

一直连接不上stmp.**.com:465的服务器时因为需要证书,而网上提供的生成证书的一个..java根本就没有用。

最后在官网上面看到了这段话。

 

Java代码   收藏代码
  1. In earlier releases it was necessary to explicitly set a socket  
  2. factory property to enable use of SSL.  In almost all cases, this  
  3. is no longer necessary.  SSL support is built in.  However, there  
  4. is one case where a special socket factory may be needed.  
  5.   
  6. JavaMail now includes a special SSL socket factory that can simplify  
  7. dealing with servers with self-signed certificates.  While the  
  8. recommended approach is to include the certificate in your keystore  
  9. as described above, the following approach may be simpler in some cases.  
  10.   
  11. The class com.sun.mail.util.MailSSLSocketFactory can be used as a  
  12. simple socket factory that allows trusting all hosts or a specific set  
  13. of hosts.  For example:  
  14.   
  15.     MailSSLSocketFactory sf = new MailSSLSocketFactory();  
  16.     sf.setTrustAllHosts(true);  
  17.     // or  
  18.     // sf.setTrustedHosts(new String[] { "my-server" });  
  19.     props.put("mail.smtp.ssl.enable""true");  
  20.     // also use following for additional safety  
  21.     //props.put("mail.smtp.ssl.checkserveridentity", "true");  
  22.     props.put("mail.smtp.ssl.socketFactory", sf);  
  23.   
  24. Use of MailSSLSocketFactory avoids the need to add the certificate to  
  25. your keystore as described above, or configure your own TrustManager  
  26. as described below.(使用MailSSLSocketFactory避免了需要添加证书,你的密钥库如上所述,或配置自己的TrustManager。如下所述。  

 实在是高兴啊。使用这个方法后马上使用SSL发送邮件的方式,发送成功了

官网还提供了一个自己实现的加密管理类,可以使用。在这里我就不贴上来了。直接上官网的地址。

http://www.oracle.com/technetwork/java/javamail145sslnotes-1562622.html

 

本人英语水凭能力不行,不能翻译。如果英语水平好。翻译出来,绝对是一个很好的资源。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值