英文:
javax.mail.MessagingException: PKIX path building failed: SunCertPathBuilderException: unable to find valid certification path to requested target;
问题
我在尝试连接到存储时遇到了这个异常。
当我查看论坛时,发现解决这个错误的方法是将证书添加到正在使用的 JVM 的信任存储文件中。
问题是我是新手,不太确定我应该如何做到这一点:我应该从哪里获取证书,如何添加它?
注:我注意到当我使用主方法运行它时,它可以正常工作!但当我设置一个调度程序来自动调用该方法时,我就会遇到这个异常。
非常感谢帮助。
异常是:
javax.mail.MessagingException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target;
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.imap.IMAPStore.protocolConnect(IMAPStore.java:479)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
以下是代码部分,无需翻译:
public void receiveMails() throws Exception
{
Properties props = new Properties();
props.setProperty("mail.store.protocol", "imaps");
props.setProperty("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.imaps.socketFactory.fallback", "false");
props.setProperty("mail.imaps.ssl.enable", "false");
props.setProperty("mail.imaps.socketFactory.port", "993");
props.setProperty("mail.imaps.starttls.enable", "true");
props.setProperty("mail.imaps.ssl.trust", "mailHost");
try
{
Session session = Session.getInstance(props, null);
Store store = session.getStore();
store.connect("mailHost", "user@domain.com", "password");
//...
}
}
英文:
I get this Exception when I try to connect to the store.
As I look through forums, the solution to this error is to add the certificate to the truststore file of the used JVM.
The problem is I am new to this and I am not sure that I understand how I should do this exactly: Where should I get the certificate and how should I add it?
N.B: I notice that when I run this using main method, it works fine! But when I set a Scheduler to call the method automatically, that's when I get the exception.
Thank you a lot for the help.
public void receiveMails() throws Exception
{
Properties props = new Properties();
props.setProperty("mail.store.protocol", "imaps");
props.setProperty("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.imaps.socketFactory.fallback", "false");
props.setProperty("mail.imaps.ssl.enable", "false");
props.setProperty("mail.imaps.socketFactory.port", "993");
props.setProperty("mail.imaps.starttls.enable", "true");
props.setProperty("mail.imaps.ssl.trust", "mailHost");
try
{
Session session = Session.getInstance(props, null);
Store store = session.getStore();
store.connect("mailHost", "user@domain.com", "password");
//...
The Exception is:
javax.mail.MessagingException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target;
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.imap.IMAPStore.protocolConnect(IMAPStore.java:479)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
答案1
得分: 2
尝试在进行此操作时禁用您的防病毒软件。这可能是问题的原因。
英文:
Try disabling your antivirus while doing this operation. This might be the cause.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论