File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes unable to find valid certification path to requested target Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "unable to find valid certification path to requested target " Watch "unable to find valid certification path to requested target " New topic
Author

unable to find valid certification path to requested target

keerthana kuruba
Greenhorn

Joined: May 12, 2011
Posts: 22

Hi,

this is my java program to read email message from gmail inbox.But when ever run this program am getting below error.
Here i have checked the cacerts in JDK folder path(C:\Program Files\Java\jdk1.6.0_23\jre\lib\security\cacerts).still getting this error.Before i have compiled and run the email sending program successfully.


C:\Program Files\Java\jdk1.6.0_23\bin>javac ReadMail.java

C:\Program Files\Java\jdk1.6.0_23\bin>java ReadMail
javax.mail.MessagingException: Connect failed;
nested exception is:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorExc
eption: PKIX path building failed: sun.security.provider.certpath.SunCertPathBui
lderException: unable to find valid certification path to requested target

Kindly help me how to solve this error. java version is JDK1.6.set mail.jar in classpath.Here is my code

ReadMail.java
----------------------------------------------------------------

import java.io.IOException;
import java.io.FileWriter;
import java.security.*;
import java.util.Properties;
import javax.mail.*;
import com.sun.mail.pop3.POP3SSLStore;
import javax.mail.internet.*;
import javax.mail.Transport;


public class ReadMail
{
public static void main(String args[]) throws IOException
{
Properties properties = System.getProperties();
properties.put("mail.smtp.starttls.enable", "true");
properties.setProperty("mail.store.protocol", "pop3s");
properties.put("mail.smtp.auth", "true");


try
{
Session session = Session.getDefaultInstance(properties, null);
//create session instance
Store store = session.getStore("pop3s");//create store instance
store.connect("pop.gmail.com", "keerthana.kuruba@gmail.com", "xxxxxxxxxx");
//set your user name and password
System.out.println(store);
Folder inbox = store.getFolder("inbox");
//set folder from where you wants to read mails
inbox.open(Folder.READ_ONLY);//set access type of Inbox
Message messages[] = inbox.getMessages();// gets inbox messages

for(Message message:messages)
{
System.out.println(message.getContent().toString());
}
store.close();
}
catch (Exception e)
{
System.out.println(e);
}
}

}

-------------------------------------------

Thanks

keerthana
keerthana kuruba
Greenhorn

Joined: May 12, 2011
Posts: 22
I solved this exception by adding one method to the program.that is props.put("mail.pop3s.ssl.trust","*");//for the certification exception

Thanks a lot....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unable to find valid certification path to requested target