在执行以下行时连接到我的邮件服务器时出现以下异常
transport.connect("test.mailserver.com",465,"test.user@test.com","testpwd");
例外是:
(javax.mail.MessagingException) javax.mail.MessagingException: Exception reading response;
nested exception is:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: subject/issuer name chaining check failed
下面是代码:
protected static Session initializeSession(MailMessage p_msg) throws Exception{
//Get the SMTP Host
Properties prop = System.getProperties();
prop.put( "mail.smtps.host", "test.mailserver.com" );
prop.put("mail.transport.protocol", "smtps");
prop.put("mail.smtps.auth", true);
Session session = Session.getInstance(prop,null);
session.setDebug( p_msg.getDebugMode() );
return session;
}
protected static void sendMessage(MimeMessage p_msg) throws Exception{
Properties prop = System.getProperties();
Session session = Session.getDefaultInstance(prop, null);
Transport transport = session.getTransport("smtps");
transport.connect("test.mailserver.com",465,"test.user@test.com","testpwd");
transport.sendMessage(p_msg, p_msg.getAllRecipients());
transport.close();
}