2013-05-29 23 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

请人帮忙吗? –

相关问题