java mail Received fatal alert: handshake_failure java 无法发送邮件问题 java 发送qq邮件(含源码)
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邮件(含源码)的更多相关文章
- 解决idea gradle构建Received fatal alert: handshake_failure问题
Gradle是一款强大的构建工具,但是搭建项目运行环境总是非常头痛,各种网络原因会导致项目不能成功的导入. 说一下这个问题的解决办法,折腾了很久终于解决了. javax.net.ssl.SSLHand ...
- jdk1.7访问https报javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure问题解决
本地jdk版本java version "1.8.0_31",代码中已对https做了相应处理:信任所有来源证书,运行正常:上包到服务器(服务器jdk版本java version ...
- 转:javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 解决方案
转:javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 解决方案javax.net.ssl.SSL ...
- 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 ...
- 处理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- ...
- javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
SSL握手失败:用JDK1.8做发邮件的功能遇到这种问题处理方式是:将目录 %JAVA_HOME%\...\jre\lib\security里的local_policy.jar,US_export_p ...
- javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure 解决方案
这个是jdk导致的,jdk里面有一个jce的包,安全性机制导致的访问https会报错,官网上有替代的jar包,换掉就好了 目录 %JAVA_HOME%\jre\lib\security里的local_ ...
- Centos7编译hadoop异常:Received fatal alert: handshake_failure
保持网络畅通 或者 配置代理 能够访问cdh的仓库 https://repository.cloudera.com/artifactory/cloudera-repos/ 编译hadoop版本 had ...
- 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: ...
随机推荐
- Vue实例和生命周期
创建一个Vue实例 每个Vue应用都是通过Vue函数创建一个新的Vue实例开始: var vm = new Vue({ //选项 }) 数据与方法 当一个Vue实例被创建时,它向Vue的响应式系统中加 ...
- Decorator——Python初级函数装饰器
最近想整一整数据分析,在看一本关于数据分析的书中提到了(1)if __name__ == '__main__' (2)列表解析式 (3)装饰器. 先简单描述一下前两点,再详细解说Python初级的函数 ...
- Tourists Gym - 101002I LCA——dfs+RMQ在线算法
LCA(Least Common Ancestors),即最近公共祖先,是指这样一个问题:在有根树中,找出某两个结点u和v最近的公共祖先(另一种说法,离树根最远的公共祖先). 知识需求:1)RMQ的S ...
- servlet 作用
什么是Servlet Servlet是一个Java编写的程序,此程序是基于Http协议的,在服务器端运行的(如tomcat),是按照Servlet规范编写的一个Java类. 在BS架构中,早期的Web ...
- 串口编程的相关API函数
用户使用函数CreateFile()创建与指定串口相关联的文件,然后可以使用该函数返回的文件句柄进行串口参数设置.• 01 HANDLE hModem; //定义串口句柄02 hModem=Creat ...
- 重新造轮子之静态链接1(Static linking)
最近学习计算机病毒学的过程中,又讲到了静态链接的问题,联想到了之前保健哥在信息安全的课堂上向我们展示了一个没有main()函数的C程序到底应该如何编写.个人觉得这个小实验对于加深静态链接的过程的理解也 ...
- 精通CSS高级Web标准解决方案(2-2 可视化格式模型之定位概述)
视觉格式化模型 块级元素(块框).行内元素(行内框),可以使用display改变生成的框的类型,display:block让行内元素(比如<a>)表现的跟块级元素一样,display:no ...
- DS作业06-图
1.本周学习总结(0--2分) 1.1思维导图 1.2谈谈你对图结构的认识及学习体会. 图这一章的学习,是经过树学习后,难得一章重新寻找到感觉的学习.因为这一章比较少用递归,使用的是结构体,很多东西我 ...
- 【Luogu】P3786萃香抱西瓜(状压DP)
题目链接 水题,数据范围提示得太明显了吧,不用动脑子都能知道是状压. 不过还是有坑(当然更可能是我脑子有坑) f[i][j][k][l]表示当前是第i秒,萃香在(j,k),已经抱到的西瓜状态是l的最少 ...
- HDU-2853 Assignment
求二分最大匹配,但还要尽量接近原匹配... 解决方法:对于N个顶点的二分图,每条边同时乘上一个比N稍微大的数N',然后对于在原匹配的边就都+1. 经过这样处理,求得的答案Ans乘除N'即是原图的最大匹 ...