首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

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

2013-07-26 
javamail 关于SSL的问题找了我一个星期之久关于javamail 使用SSl方式发送邮件的问题。我在官网上面终于找到

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

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

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

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

?

In earlier releases it was necessary to explicitly set a socketfactory property to enable use of SSL.  In almost all cases, thisis no longer necessary.  SSL support is built in.  However, thereis one case where a special socket factory may be needed.JavaMail now includes a special SSL socket factory that can simplifydealing with servers with self-signed certificates.  While therecommended approach is to include the certificate in your keystoreas described above, the following approach may be simpler in some cases.The class com.sun.mail.util.MailSSLSocketFactory can be used as asimple socket factory that allows trusting all hosts or a specific setof hosts.  For example:    MailSSLSocketFactory sf = new MailSSLSocketFactory();    sf.setTrustAllHosts(true);    // or    // sf.setTrustedHosts(new String[] { "my-server" });    props.put("mail.smtp.ssl.enable", "true");    // also use following for additional safety    //props.put("mail.smtp.ssl.checkserveridentity", "true");    props.put("mail.smtp.ssl.socketFactory", sf);Use of MailSSLSocketFactory avoids the need to add the certificate toyour keystore as described above, or configure your own TrustManageras described below.(使用MailSSLSocketFactory避免了需要添加证书,你的密钥库如上所述,或配置自己的TrustManager。如下所述。

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

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

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

?

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

?

热点排行