2013-05-29 52 views
0
String to="[email protected]";//change accordingly 

//Get the session object 
Properties props = new Properties(); 
props.put("mail.smtp.host", "smtp.gmail.com"); 
props.put("mail.smtp.socketFactory.port", "465"); 
props.put("mail.smtp.socketFactory.class", 
     "javax.net.ssl.SSLSocketFactory"); 
props.put("mail.smtp.auth", "true"); 
props.put("mail.smtp.port", "465"); 

Session sess = Session.getInstance(props, 
new javax.mail.Authenticator() { 
protected PasswordAuthentication getPasswordAuthentication() { 
return new PasswordAuthentication("[email protected]","password");//change accordingly 
} 
}); 

//compose message 
try { 
MimeMessage message = new MimeMessage(sess); 
message.setFrom(new InternetAddress("[email protected]"));//change accordingly 
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to)); 
message.setSubject("Hello"); 
message.setText("Testing......."); 

//send message 
Transport.send(message); 

System.out.println("message sent successfully"); 

} 
catch (MessagingException e) { 
    out.println(e);} 

在發送郵件Java的SSL:無法找到請求的目標

javax.mail.MessagingException的我收到以下錯誤有效證書路徑:異常讀數響應;嵌套的例外是:javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路徑建設失敗:sun.security.provider.certpath.SunCertPathBuilderException:無法找到請求的目標的有效證書路徑

+1

添加屬性'props.put(「mail.pop3s.ssl.trust」,「*」);'並檢查。 – NINCOMPOOP

+0

不,我仍然得到相同的異常 –

+0

如果你用google搜索錯誤信息,你會發現幾十個(數百)命中。您必須將相應的CA證書添加到Java密鑰庫。請參閱http://www.mikepilat.com/blog/2011/05/adding-a-certificate-authority-to-the-java-runtime/ –

回答

0

嘗試這個!

Properties props = new Properties(); 
    props.put("mail.smtp.host", "smtp.xyz.in"); 
    props.put("mail.smtp.socketFactory.port", "25"); 

    props.put("mail.smtp.auth", "true"); 
    props.put("mail.smtp.port", "25"); 
    props.put("mail.smtp.dsn.notify", 
       "SUCCESS ORCPT=rfc822;"); 
    props.put("mail.smtp.dsn.ret", "FULL"); 
+0

我現在收到此錯誤, javax.mail.MessagingException:異常閱讀反應;嵌套異常是:javax.net.ssl.SSLException:無法識別的SSL消息,明文連接? –

+0

請人幫忙嗎? –

相關問題