Ich versuche, Mail mit SMTP zu senden, die als Standard-SMTP-Server mit 25.587 Ports und TLS festgelegt. MS Exchange 2010. Alle Authentifizierungsdaten sind korrekt, weil ich mich über die Web-Schnittstelle der Mail einloggen kann. Code unten funktioniert mit gmail SMTP-Server arbeiten, aber wenn ich meinen eigenen SMTP-Server verwenden, es wirft mir Fehler mit cert Pfaden:TLS SMTP-Mail-Java löst SSLHandShakeException
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX Weg Gebäude fehlgeschlagen: sun.security.provider.certpath.SunCertPathBuilderException: nicht in der Lage zu finden angeforderte Ziel gültigen Zertifizierungspfad
public static void SendMailTLS(String to, String subject, String body) throws Exception{
try {
java.util.Properties props = new java.util.Properties();
props.put("mail.smtp.host", "sample");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.connectiontimeout", "10000");
final String EmailUser = "sample";
final String EmailPassword = "sample";
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
EmailUser,EmailPassword);
}
}); session.setDebug(true);
InternetAddress fromAddress = new InternetAddress("sample",
"sample");
InternetAddress toAddress = new InternetAddress("sample",
"sample");
Message msg = new MimeMessage(session);
msg.setFrom(fromAddress);
msg.addRecipient(Message.RecipientType.TO,toAddress);
msg.setSubject(subject);
msg.setText(body);
Transport transport = session.getTransport("smtp");
transport.connect();
transport.sendMessage(msg, msg.getAllRecipients());
} catch (MessagingException e) {e.printStackTrace();}
}
Bin ich etwas falsch?