• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unable to find valid certification path to requested target

 
keerthana kuruba
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic