av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

JavaMail 發(fā)送郵件失敗

瀏覽:105日期:2023-12-14 16:29:59

問(wèn)題描述

用java 實(shí)現(xiàn)一個(gè) 發(fā)送郵件的Demo(用的是QQ郵箱) 但發(fā)送總是失敗,QQ郵箱中的 Smtp 服務(wù)也都開(kāi)啟了,密碼用的是獲取的授權(quán)碼

public static void main(String[] args) { // 收件人電子郵箱 String to = '123@qq.com'; // 發(fā)件人電子郵箱 String from = '456@qq.com'; // 指定發(fā)送郵件的主機(jī)為 smtp.qq.com String host = 'smtp.qq.com'; //QQ 郵件服務(wù)器 // 獲取系統(tǒng)屬性 Properties properties = System.getProperties(); // 設(shè)置郵件服務(wù)器 properties.setProperty('mail.smtp.host', host); properties.put('mail.smtp.auth', 'true'); properties.put('mail.smtp.port', '465'); properties.put('mail.smtp.socketFactory.port', '465'); properties.put('mail.smtp.socketFactory.class', 'javax.net.ssl.SSLSocketFactory'); properties.put('mail.smtp.starttls.enable', 'true'); properties.put('mail.smtp.socketFactory.fallback', 'false'); properties.put('mail.smtp.starttls.enable', 'true'); properties.put('mail.smtp.ssl.trust', 'smtp.qq.com'); // 獲取默認(rèn)session對(duì)象 Session session = Session.getDefaultInstance(properties,new Authenticator(){ public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication('456@qq.com', '123123'); //發(fā)件人郵件用戶名、密碼 } }); session.setDebug(true); try{ // 創(chuàng)建默認(rèn)的 MimeMessage 對(duì)象 MimeMessage message = new MimeMessage(session); // Set From: 頭部頭字段 message.setFrom(new InternetAddress(from)); // Set To: 頭部頭字段 message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); // Set Subject: 頭部頭字段 message.setSubject('This is the Subject Line!'); // 設(shè)置消息體 message.setText('This is actual message'); // 發(fā)送消息 Transport.send(message); System.out.println('Sent message successfully....from w3cschool.cc'); }catch (MessagingException mex) { mex.printStackTrace(); } }

錯(cuò)誤提示DEBUG SMTP: trying to connect to host 'smtp.qq.com', port 465, isSSL falsejavax.mail.MessagingException: Could not connect to SMTP host: smtp.qq.com, port: 465; nested exception is:

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested targetat com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1972)at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:642)at javax.mail.Service.connect(Service.java:317)at javax.mail.Service.connect(Service.java:176)at javax.mail.Service.connect(Service.java:125)at javax.mail.Transport.send0(Transport.java:194)at javax.mail.Transport.send(Transport.java:124)at com.syx.email.MailTest3.main(MailTest3.java:68)

有沒(méi)有做過(guò)類(lèi)似的大神指點(diǎn)一下 …^.^…

問(wèn)題解答

回答1:

SSL數(shù)字證書(shū)問(wèn)題,簡(jiǎn)單點(diǎn)去掉數(shù)字證書(shū)驗(yàn)證試試 properties.put('mail.smtp.ssl.trust', 'smtp.qq.com'); // 這行先注釋調(diào)

標(biāo)簽: java
相關(guān)文章:
主站蜘蛛池模板: 久久久久国产一区二区三区 | 天海翼一区二区 | 日本在线网站 | av免费网站 | 亚色视频| 久久久久久亚洲 | 在线播放中文字幕 | 1级黄色大片 | 综合色av| 成 人 黄 色 片 在线播放 | 久久手机免费视频 | 日本欧美久久久久免费播放网 | 一级片免费在线观看 | 国产香蕉av | 国产精品久久久精品 | 欧美成人毛片 | 久久久久久网 | av在线资源网| 国产伦精品一区二区三区88av | 成人午夜在线观看 | 91久久久久国产一区二区 | 欧美一区二区免费 | 色激情网 | 色老板免费视频 | 欧美日韩一区二区在线 | 日韩一区二区三区av | 97国产精品视频 | 蜜臀久久99精品久久久久宅男 | 青青操影院 | 久久精品中文 | 国产一二区 | 黄色在线小视频 | 综合久久综合 | 国产精品久久一区二区三区 | 97视频免费 | 中文字幕在线观看日本 | 亚洲综合二区 | av免费在线观看网站 | 欧美特黄| 一区二区免费在线观看 | 青青五月天 |