【问题标题】:Java SSL: unable to find valid certification path to requested target [duplicate]Java SSL:无法找到请求目标的有效证书路径[重复]
【发布时间】:2013-05-24 23:24:10
【问题描述】:
String to="mydaman7291@gmail.com";//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("daman.bonnie07@gmail.com","password");//change accordingly
 }
});

//compose message
try {
 MimeMessage message = new MimeMessage(sess);
 message.setFrom(new InternetAddress("daman.bonnie07@gmail.com"));//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);}

发送邮件时出现以下错误

javax.mail.MessagingException:异常读取响应;嵌套异常是:javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径

【问题讨论】:

  • 添加属性props.put("mail.pop3s.ssl.trust","*");并检查。
  • 不,我仍然遇到同样的异常
  • 如果您搜索了错误消息,您会发现数十(数百)条点击。您必须将适当的 CA 证书添加到 Java 密钥库。见mikepilat.com/blog/2011/05/…

标签: java jsp gmail jakarta-mail


【解决方案1】:

试试这个!

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");

【讨论】:

  • 我现在收到这个错误,javax.mail.MessagingException: Exception reading response;嵌套异常是:javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
  • 请人帮忙?
猜你喜欢
  • 1970-01-01
  • 2014-05-26
  • 2020-03-01
  • 2017-09-19
  • 2011-11-12
  • 1970-01-01
  • 1970-01-01
  • 2020-11-11
  • 2011-10-18
相关资源
最近更新 更多