使用QQ邮箱发送邮件遇到的问题
代码是在网上抄的别人今年写的,但是我运行起来一直报错,也不知道什么原因,请大神帮忙指点一下;;谢谢!!!
以下是我的代码
public class Sendmail8 {
public static void main(String[] args) throws MessagingException, GeneralSecurityException {
Properties props = new Properties();
// 开启debug调试
props.setProperty("mail.debug", "true");
// 发送服务器需要身份验证
props.setProperty("mail.smtp.auth", "true");
// 设置邮件服务器主机名
props.setProperty("mail.host", "");
// 发送邮件协议名称
props.setProperty("mail.transport.protocol", "smtp");
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);
Message msg = new MimeMessage(session);
msg.setSubject("seenews 错误");
StringBuilder builder = new StringBuilder();
builder.append("url = " + "/never_cxb/article/details/50524571");
builder.append("\n页面爬虫错误");
// builder.append("\n时间 " + TimeTool.getCurrentTime());
msg.setText(builder.toString());
msg.setFrom(new InternetAddress("90***867@"));
Transport transport = session.getTransport();
transport.connect("", "90***867@", "ymyrj*****mybgab");
transport.sendMessage(msg, new Address[] { new InternetAddress("lu*****23@") });
transport.close();
}
}
然后运行报的异常
Exception in thread "main" javax.mail.MessagingException: Could not connect to SMTP host: , port: 465;
nested exception is:
.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1961)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at com.oracel.mail01.Sendmail8.main(Sendmail8.java:48)
Caused by: .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:549)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:354)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:237)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1927)
... 4 more
相关阅读:
在对象上定义函数
TP为什么返回的数据一直都是array??
JSTL重点标签!
有什么好的javascript项目可以练习吗
animation动画
[cordova]安卓手机已经开启开发者选项,为何在WebStorm中点Run后无法输出到手机中运行,提示权限被拒?
nginx配置根目录失败
内容量大的网站是如何加载页面的?
python selenium2 警告框处理- 接受现有警告框、问题?
xampp找不到php5.ini文件,怎么解决?
nginx多站点配置,无法通过域名访问,使用ip访问会跳转到其中一个站点
关于挂机游戏的问题
express compression中间件需要配合nginx使用吗?不能单独使用吗?
php抛出异常后捕获不到
npm run dev报错
为什么说druid是最好的数据库连接池
quick-cocos2d-x 3.6中如何调用webview
jQuery 源码中X-Requested-With header 的作用
input[type=file] 第一次点击它,并且点击取消的按钮,onchange事件不触发,那么如何获取该事件?
php实现16位的des加密
如果觉得《java发送qq邮箱不成功_java _使用QQ邮箱发送邮件遇到的问题 java - phpStudy》对你有帮助,请点赞、收藏,并留下你的观点哦!