关于javamail 使用SSl方式发送邮件的问题。我在官网上面终于找到答案了。
一直连接不上stmp.**.com:465的服务器时因为需要证书,而网上提供的生成证书的一个..java根本就没有用。
最后在官网上面看到了这段话。
In earlier releases it was necessary to explicitly set a socket factory property to enable use of SSL. In almost all cases, this is no longer necessary. SSL support is built in. However, there is one case where a special socket factory may be needed. JavaMail now includes a special SSL socket factory that can simplify dealing with servers with self-signed certificates. While the recommended approach is to include the certificate in your keystore as described above, the following approach may be simpler in some cases. The class com.sun.mail.util.MailSSLSocketFactory can be used as a simple socket factory that allows trusting all hosts or a specific set of 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 to your keystore as described above, or configure your own TrustManager as described below.(使用MailSSLSocketFactory避免了需要添加证书,你的密钥库如上所述,或配置自己的TrustManager。如下所述。
使用这个方法后马上使用SSL发送邮件的方式,发送成功了。真心不容易。
官网还提供了一个自己实现的加密管理类,可以使用。在这里我就不贴上来了。直接上官网的地址。
http://www.oracle.com/technetwork/java/javamail145sslnotes-1562622.html
相关推荐
如何用javamail定时发送邮件
如何用javamail定时发送邮件.doc
使用JAVAMail代发邮件 资源源于不但搜索,自由源于不但努力
Spring整合JavaMail发送qq邮件,极简单的例子。看完就会。。。
javaMail发送邮件 发送成功 收不到邮件 或收到邮件无主题无收件人乱码 查看debug 邮件处理过程发现邮件头没有编译, 内容是base64编码,所以邮箱收不到或者收到的是base64编码后的一堆乱码,
怎么用JavaMail收取邮件.doc怎么用JavaMail收取邮件.doc
NULL 博文链接:https://surpass-li.iteye.com/blog/1100515
javamail 发送收取邮件
javamail实现发送邮件的小例子,简单易会,好用记得给好评哦!
javamail发送邮件实例 javamail 发送邮件 文本编辑器 kindeditor
JSP与JavaMail发送HTML格式... java,javamail发送html邮件..
用到的两个包 mail.jar activation.jar 博文链接:https://seawavecau.iteye.com/blog/108929
Android用JavaMail发送邮件
Struts2框架,javamail发送邮件,可以直接用main()调用,也可通过tomcat,在IE上运行,比较简单易懂。
利用JAVAMAIL实现的发送邮件的小例子
javamail批量发送邮件
此源码是使用javamail发送邮件,可以实现静默发送邮件,可以发送附件资源等。有相应的使用说明,快捷好用
用JavaMail发送邮件用到的类简介以及一个完整的程序。
Javamail发送邮件类库,Java发送邮件需要用到该类库