我创建了一个Java应用程序,可以从我的Gmail收件箱中读取邮件。我的代码很好,但是当我执行代码时,我在控制台上出现以下错误。有人可以启发我并提供解决方案吗?
**javax.mail.MessagingException: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException:** **Path does not chain with any of the trust anchors;**
nested exception is:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:665)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at pkg.RetrieveEmail.main(RetrieveEmail.java:21)
import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;
public class RetrieveEmail {
public static void main(String[] args) {
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
try{
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("imap.gmail.com", "someone@gmail.com", "xxxx");
System.out.println(store);
Folder inbox = store.getFolder("Inbox");
inbox.open(Folder.READ_ONLY);
Message messages[] = inbox.getMessages();
for(Message message : messages){
System.out.println(message.getSubject());
}
}catch(MessagingException e){
e.printStackTrace();
System.exit(2);
}catch(Exception e1){
e1.printStackTrace();
}
}
}