java send mail on Linux: Error certification
<p>I try to send mail by Java on Linux server.
I setup to run on Tomcat 6, config SSL
but I got an error message: </p>

<pre><code> Can't send command to SMTP host 
 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
</code></pre>

<p>My java code like below:</p>

<pre><code>    String host = "smtp.gmail.com";
    int port = 587;
    String username = "java.test@gmail.com";
    String password = "aabbcc";

    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");

    Session session = Session.getInstance(props);

    try {


        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("java.test@gmail.com"));
        message.setRecipients(Message.RecipientType.TO,
            InternetAddress.parse("test504@gmail.com"));
        message.setSubject("Testing Subject");
        message.setText("Dear Mail Crawler," +
                "\n\n No spam to my email, please!");


        Transport transport = session.getTransport("smtp");
        transport.connect(host, port, username, password);


        Transport.send(message);

        System.out.println("Done");

    } catch (MessagingException e) {
        System.out.println("ERROR: "+e.getMessage());
        System.out.println("ERROR: "+e.toString());

        throw new RuntimeException(e);
    }
</code></pre>

<p>If I config Tomcat without SSL -> It can send mail Success
But within SSL -> I have above error</p>

<p>Please help fix error. Thank guys!</p>
