您的位置:首页 > 编程语言 > Java开发

发送邮件Javax.mail.AuthenticationFailedException: 530 Error:

2018-03-07 11:44 1716 查看
    今天写的小demo里有一个发送QQ邮件验证码的功能。心想着照着以前的代码改就是了(以前用的不是QQ邮箱)。
    结果写的时候发现了一个问题,一直会报javax.mail.AuthenticationFailedException: 530 Error: A secure connection is requiered(such as ssl). More information at http://service.mail.qq.com/cgi-bin/help?id=28的错误。         百度了一下发现如果使用QQ邮箱发送,需要进行SSL加密,如果没有加密,就会报530的错误。

SSL加密代码: //定义Properties对象,设置环境信息
Properties props = new Properties();

try {

MailSSLSocketFactory sf = new MailSSLSocketFactory();
sf.setTrustAllHosts(true);
props.put("mail.smtp.ssl.enable", "true");
props.put("mail.smtp.ssl.socketFactory", sf);
} catch (GeneralSecurityException e1) {
e1.printStackTrace();
}加上这段代码后就不会再报530的问题啦~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐