Javaを使用してZimbra Mail Serverにメールを送信しているときにRuntimeExceptionを取得できません。Javaが有効な証明書を見つけることができません
は、ここに私のJava
クラスTest.java
public class Test {
public static void main(String[] args) {
sendMail("[email protected]","Test","Test Message",null);
}
public static Properties getMailProperties() {
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.bevmi.com");
props.put("mail.smtp.port", "587");
return props;
}
public static boolean sendMail(String to, String subject,String text,String cc) {
final String username = "[email protected];
final String password = "password";
Properties props = getMailProperties();
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
message.setSender(new InternetAddress("[email protected]"));
if ((cc!=null) && (!cc.isEmpty())) {
message.setRecipients(Message.RecipientType.CC, InternetAddress.parse(cc));
}
message.setSubject(subject);
message.setText(text, "UTF-8", "html");
System.out.println("Sending Message to :" + to);
Transport.send(message);
System.out.println("Email Sent");
return true;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
であり、私は私の "メイン" スレッドで次のRuntimeExceptionのスタックトレースを得ました。
java.lang.RuntimeException: javax.mail.MessagingException: Could not convert socket to TLS; 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 at Test.sendMail(Test.java:57) at Test.main(Test.java:13)