hello all
I use JavaMailAPI for sending mail on my web application and write a servlet and use this codes for sending mail on that sevlet
Java Code:
Properprops = new Properties();
        props.setProperty("mail.transport.protocol", "smtp");
        props.setProperty("mail.host", "smtp.salekanpublishing.ir");
        props.setProperty("mail.mime.charset", "UTF-8");
        props.setProperty("mail.smtp.auth", "true");
        props.setProperty("mail.smtp.starttls.enable", "true");
        SMTPAuthenticator auth = new SMTPAuthenticator();
        mailSession=Session.getDefaultInstance(props, auth);
        message=new MimeMessage(mailSession);
        try {
            message.setFrom(new InternetAddress(USER));
            Address addressTo[]=new Address[1];
            for (int i = 0; i < addressTo.length; i++) {
                addressTo[i]=new InternetAddress("iman.esmaeili.14@gmail.com");
            }
            message.setRecipients(Message.RecipientType.TO, addressTo);
            message.setSubject("test mail");
            message.setContent("<table>" +
                    "<tr><td>test mail</td></tr>"+
                    "<tr><td>this is a test mail</td></tr>" +
                    "</table>", "text/html; charset=UTF-8");
            Transport.send(message);
            out.print("email sent correctly");
        } catch (AddressException ex) {
            out.print("the address is incorrect");
            Logger.getLogger(mainForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MessagingException ex) {
            out.print("sending email failed");
            Logger.getLogger(mainForm.class.getName()).log(Level.SEVERE, null, ex);
        }
and the below method called from above code
Java Code:
private class SMTPAuthenticator extends javax.mail.Authenticator{
        public PasswordAuthentication getPasswordAuthentication()
        {
            String username = "MyUsername";
            String password = "MyPassword";
            return new PasswordAuthentication(username, password);
        }
    }
but when i call and execute this servlet the below exception thrown
Java Code:
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 com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1652)
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:534)
        at javax.mail.Service.connect(Service.java:313)
        at javax.mail.Service.connect(Service.java:172)
        at javax.mail.Service.connect(Service.java:121)
        at javax.mail.Transport.send0(Transport.java:190)
        at javax.mail.Transport.send(Transport.java:120)