午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術文章
文章詳情頁

JavaMail 發送郵件失敗

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

問題描述

用java 實現一個 發送郵件的Demo(用的是QQ郵箱) 但發送總是失敗,QQ郵箱中的 Smtp 服務也都開啟了,密碼用的是獲取的授權碼

public static void main(String[] args) { // 收件人電子郵箱 String to = '123@qq.com'; // 發件人電子郵箱 String from = '456@qq.com'; // 指定發送郵件的主機為 smtp.qq.com String host = 'smtp.qq.com'; //QQ 郵件服務器 // 獲取系統屬性 Properties properties = System.getProperties(); // 設置郵件服務器 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'); // 獲取默認session對象 Session session = Session.getDefaultInstance(properties,new Authenticator(){ public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication('456@qq.com', '123123'); //發件人郵件用戶名、密碼 } }); session.setDebug(true); try{ // 創建默認的 MimeMessage 對象 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!'); // 設置消息體 message.setText('This is actual message'); // 發送消息 Transport.send(message); System.out.println('Sent message successfully....from w3cschool.cc'); }catch (MessagingException mex) { mex.printStackTrace(); } }

錯誤提示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)

有沒有做過類似的大神指點一下 …^.^…

問題解答

回答1:

SSL數字證書問題,簡單點去掉數字證書驗證試試 properties.put('mail.smtp.ssl.trust', 'smtp.qq.com'); // 這行先注釋調

標簽: java
相關文章:
主站蜘蛛池模板: 日韩在线 中文字幕 | 亚洲精品一线 | 免费在线观看av网站 | 成人片在线免费看 | 国产又粗又长又黄视频 | xxxxx国产 | 中文精品一区二区三区 | 免费a级黄色片 | 俺去啦最新网址 | ktv做爰视频一区二区 | 在线看片亚洲 | 大学生一级一片第一次 | 起碰在线视频 | 免费黄色国产 | 男女精品视频 | 最新日韩中文字幕 | 一道本视频在线 | 99视频热| 国产黄色自拍视频 | 中文字幕高清 | 青青青久久 | 特黄aaaaaaaaa真人毛片 | 夜夜夜夜爽 | 一级成人免费视频 | 肉视频在线观看 | 日本久久久久久久久久 | 欧美一级片在线看 | 成人深夜网站 | 日本激情小视频 | av色哟哟 | 日韩激情一区二区 | 蜜桃av一区二区 | 午夜视频免费 | 快色在线 | 午夜三级视频 | 九九精品免费 | 一本到在线视频 | 一级黄色片在线观看 | 久国产视频 | 伊人色av| 国产精成人品免费观看 |