java 无法发送邮件问题 java 发送qq邮件 报错:java mail Received fatal alert: handshake_failure (使用ssl)

javax.mail.MessagingException: Could not connect to SMTP host: smtp.qq.com, port: 465;
  nested exception is:
    javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
    at javax.mail.Service.connect(Service.java:295)
    at javax.mail.Service.connect(Service.java:176)
    at com.gzbugu.common.tools.ext.StringUtil.main(StringUtil.java:524)
Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
    at sun.security.ssl.Alerts.getSSLException(Unknown Source)
    at sun.security.ssl.Alerts.getSSLException(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.recvAlert(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:507)
    at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:238)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
    ... 4 more

找了半天终于解决了:

换掉本地jdk(安装目录jre\lib\security里的local_policy.jar,US_export_policy.jar)里面有一个jce的包,安全性机制导致的访问https会报错。

如本人安装的jdk需要替换的地方:1. C:\Program Files\Java\jdk1.8.0_102\jre\lib\security  2. C:\Program Files\Java\jre1.8.0_102\lib\security

下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html

目录 %JAVA_HOME%\jre\lib\security里的local_policy.jar,US_export_policy.jar

源码:

public static void main(String[] args) {
         try {
  
             //这里使用的是qq邮箱发送
        String email="xxxxxxx@qq.com";
        String pwd="cgXXXXwqfaakcjgf";//非QQ邮箱密码;是qq邮箱安全码
        
        String toemail="xxxxxx@qq.com";//接收的邮箱
     
         Properties props = new Properties();
     
              
         // 开启debug调试
         props.setProperty("mail.debug", "true");
         // 发送服务器需要身份验证
         props.setProperty("mail.smtp.auth", "true");
         // 设置邮件服务器主机名
         props.setProperty("mail.host", "smtp.qq.com");
         // 发送邮件协议名称
         props.setProperty("mail.transport.protocol", "smtp");
       
         props.put("mail.smtp.socketFactory.port", "465");
         props.put("mail.smtp.port", "465");
         props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
 
 
       
         MailSSLSocketFactory sf = new MailSSLSocketFactory();
         sf.setTrustAllHosts(true);
         props.put("mail.smtp.ssl.enable", "true");
         props.put("mail.smtp.ssl.socketFactory", sf);
        
         Session session = Session.getInstance(props);
        session.setDebug(true);
         Message msg = new MimeMessage(session);
         msg.setSubject("http://www.cnblogs.com/qgc88");
         StringBuilder builder = new StringBuilder();
         builder.append("http://www.cnblogs.com/qgc88 " );
         builder.append("http://www.cnblogs.com/qgc88");
         builder.append("\n时间 " + new Date());
         msg.setText(builder.toString());
         msg.setFrom(new InternetAddress(email));//"**发送人的邮箱地址**"
     
         Transport transport = session.getTransport();
         transport.connect("smtp.qq.com", email, pwd);
     
         transport.sendMessage(msg, new Address[] { new InternetAddress(toemail) });//"**接收人的邮箱地址**"
         transport.close();
         
        } catch (Exception e) {
        e.printStackTrace();
        }
       }

java mail Received fatal alert: handshake_failure java 无法发送邮件问题 java 发送qq邮件(含源码)的更多相关文章

  1. 解决idea gradle构建Received fatal alert: handshake_failure问题

    Gradle是一款强大的构建工具,但是搭建项目运行环境总是非常头痛,各种网络原因会导致项目不能成功的导入. 说一下这个问题的解决办法,折腾了很久终于解决了. javax.net.ssl.SSLHand ...

  2. jdk1.7访问https报javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure问题解决

    本地jdk版本java version "1.8.0_31",代码中已对https做了相应处理:信任所有来源证书,运行正常:上包到服务器(服务器jdk版本java version ...

  3. 转:javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 解决方案

    转:javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 解决方案javax.net.ssl.SSL ...

  4. Eclipse4.6安装Tomcat插件时报错:Unable to read repository at http://tomcatplugin.sf.net/update/content.xml. Received fatal alert: handshake_failure

    错误如下: Unable to read repository at http://tomcatplugin.sf.net/update/content.xml.Received fatal aler ...

  5. 处理Https 异常记录 javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

    http://blog.csdn.net/baidu_18607183/article/details/51595330 https://blogs.oracle.com/java-platform- ...

  6. javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

    SSL握手失败:用JDK1.8做发邮件的功能遇到这种问题处理方式是:将目录 %JAVA_HOME%\...\jre\lib\security里的local_policy.jar,US_export_p ...

  7. javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 解决方案

    这个是jdk导致的,jdk里面有一个jce的包,安全性机制导致的访问https会报错,官网上有替代的jar包,换掉就好了 目录 %JAVA_HOME%\jre\lib\security里的local_ ...

  8. Centos7编译hadoop异常:Received fatal alert: handshake_failure

    保持网络畅通 或者 配置代理 能够访问cdh的仓库 https://repository.cloudera.com/artifactory/cloudera-repos/ 编译hadoop版本 had ...

  9. SSL异常javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

    jdk 7 http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html jdk 8 http: ...

随机推荐

  1. MySQL8.0.12安装及配置

    一.下载 下载页面http://dev.mysql.com/downloads/mysql/ 选择系统平台后,点击download(根据系统选择64或32位) 二.配置 1.下载成功后,解压安装包到要 ...

  2. 代理工具--fiddle

    正则匹配 1)前缀为“EXACT:”表示完全匹配:只有match=rules时,才匹配 2)无前缀表示基本搜索,表示搜索到字符串就匹配:只要match中包含了rules的字符串,即可 3)前缀为“NO ...

  3. 探讨2018年最受欢迎的15顶级Python库!

    近日,数据科学网站 KDnuggets 评选出了顶级 Python 库 Top15,领域横跨数据科学.数据可视化.深度学习和机器学习.如果本文有哪些遗漏,你可以在评论区补充. 图 1:根据 GitHu ...

  4. leetcode-5-basic

    解题思路: 设两个变量land和sink,land的值是1的数量,sink表示内部的边.result = land*4-sink*2.按行扫描得到land, 同时得到同一行中内部边的数目:然后按列扫描 ...

  5. MiniProfiler监控调试MVC5以及EntityFramework6性能

    想要通过在MVC中view中直观的查看页面加载以及后台EF执行情况,可以通过MiniProfiler小工具来实现. 但是从网上搜索的相关信息要么是MVC4下的老版本的MiniProfiler,要么就是 ...

  6. Setting title-center on "< h1> " element on Android does not work, fix

    app.scss: h1.title-center{ text-align: center!important; }

  7. ogre3d环境配置与简单程序示例

    SDK安装以及编译 1.下载SDK,地址如下 http://www.ogre3d.org/download/sdk 2.安装SDK,直接解压到相应目录,如D:/ogreSDK 3.我用的是1.8版本, ...

  8. 记一次运行spark程序遇到的权限问题

    设置回滚点在本地运行时正常,在集群时就报错,后来是发现ceshi这个目录其他用户没有写的权限,修改其他用户的权限就好了 hdfs dfs - /ceshi

  9. 03-python进阶-爬虫入门-正则

    [urllib and urllib2] 这是两个python的网络模块 内置的 提供很好的网络访问的功能. #!coding:utf-8 import urllib2 res = urllib2.u ...

  10. 让boostrap的图片轮播支持滑动效果

    因为最近开发的项目涉及到移动设备上的 HTML5 开发,其中需要实现轮播效果. 然后最快捷的方式,你知道的(Bootstrap),然后原生的 Bootstrap 的 carousel.js 插件并没有 ...