Got this Error..???
"javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:"Are you searching for the code to send a Email from java program? OR Are you stuck while sending a mail due to this exception.!!! Dont worry I will help you getting it solved.
Step 1: Disable your antivirus or firewalls until we finish this.
Here is how to disable the Avast Shields.. Similarly search for yours.
Step 2: Importing SSL Certificate into your Computer.
- Now Go to connection and open certificate information.
- Now Go to Details and Then Copy to file.
- Then just do next next next then browse for file location, give a name and save.
ok... Now we are done saving the certificate, now we need to install it. copy that certificate into C:\Program Files\Java\jdk1.8.0_25\jre\lib\security this location. if you have installed windows in c drive. After pasting, double click that and run it.
now click on Install Certificate and then just next next and finish. then you are done.
Step 3: Getting jar file from apache.
Click here to download the zip file for the jar files which are going to use in our program.
Just extract and add the commons-email-1.4.jar file to your project folder in netbeans.
Step 4: Writing the program.
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import org.apache.commons.mail.*;
- /**
- *
- * @author Bisudw
- */
- public class Sender {
- public static void main(String [] args){
- try {
- Email email = new SimpleEmail();
- email.setHostName("smtp.gmail.com");
- email.setSmtpPort(465);
- email.setSSLCheckServerIdentity(true);
- email.setStartTLSRequired(true);
- email.setAuthenticator(new DefaultAuthenticator("yourmail@gmail.com", "password"));
- email.setSSLOnConnect(true);
- email.setFrom("yourmail@gmail.com");
- email.setSubject("Test Mail");
- email.setMsg("This is a test mail.");
- email.addTo("receiver's mail@gmail.com");
- email.send();
- System.out.println("Message Sent Successfully..!!");
- } catch (EmailException ex) {
- //System.out.println("Message Sending Filed...!!!");
- Logger.getLogger(Sender.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
just run it... If you get any further errors.. Please comment below.
Thank You.