大家好,我正在尝试使用网络逻辑服务器发送电子邮件。.我可以通过运行Java main的单个文件轻松地发送电子邮件,但不能使用网络逻辑发送它。我收到以下异常信息... (

javax.mail.MessagingException: Can't send command to SMTP host;
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 target


这是我的代码:

Properties props = System.getProperties();
props.put("mail.smtp.user", SMTP_AUTH_USER);
props.put("mail.smtp.password", SMTP_AUTH_PWD);
props.setProperty("mail.transport.protocol", "smtp");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.imaps.ssl.trust", "*");
props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
         return new PasswordAuthentication(SMTP_AUTH_USER, SMTP_AUTH_PWD);
   }
});


 System.out.println("Created session");
 session.setDebug(true);

  Transport transport = session.getTransport("smtp");
  System.out.println("Got Transport from session");


  MimeMessage message = new MimeMessage(session);
  message.setSubject("Movies Store Ticket Confirmation");
  message.setContent("  Dear Farish,\n \n Your Ticket Booking is Confirmed. Thank you for booking the ticket.\n \n " +
      "Movie name   : EndGame \n " +
      "Theater Name : Mstore \n " +
      "Screen       : Screen A \n " +
      "Selected Seat: B04 B05 \n " +
      "Amount       : 160 \n " +
      "Show Date    : 05/07/2014 \n " +
      "Show Time    : 10:00 AM  ", "text/plain");
  message.setFrom(new InternetAddress("******@gmail.com"));
  message.addRecipient(Message.RecipientType.TO,
       new InternetAddress("********@gmail.com"));
  System.out.println("Before Connecting");
  transport.connect(SMTP_HOST_NAME,SMTP_AUTH_USER,SMTP_AUTH_PWD);
  System.out.println("After Connecting");
  transport.sendMessage(message,
      message.getRecipients(Message.RecipientType.TO));
  System.out.println("After Sensing");
  transport.close();

}


有人请帮我...
提前致谢...

最佳答案

看到异常,您正在尝试使用需要安全证书的受保护服务器发送电子邮件。查看电子邮件服务器文档,以了解如何在程序中启用安全性问题。

10-06 05:34
查看更多