gpt4 book ai didi

java - 如何使用 Apache Camel + SSL 接收电子邮件?

转载 作者:行者123 更新时间:2023-12-05 01:18:04 26 4
gpt4 key购买 nike

我正在尝试通过 IMAPS 使用 Apache Camel 阅读电子邮件。

编辑:服务器正在使用自签名证书。我已经配置了一个 keystore 并验证了它可以通过 JavaMail 工作。

我已关注所载信息 herehere配置 Apache Camel 以使用带有自签名证书的 keystore 。

这是我的测试代码:

    @Test
public void test() throws Exception {
System.setProperty("javax.net.debug", "all");

DefaultCamelContext camelContext;

KeyStoreParameters ksp = new KeyStoreParameters();
ksp.setResource("src/test/resources/config/ssl/keystore");
ksp.setPassword("password");
TrustManagersParameters tmp = new TrustManagersParameters();
tmp.setKeyStore(ksp);
SSLContextParameters scp = new SSLContextParameters();
scp.setTrustManagers(tmp);
SimpleRegistry registry = new SimpleRegistry();
registry.put("sslContextParameters", scp);

camelContext = new DefaultCamelContext(registry);

RouteBuilder route = new RouteBuilder() {

@Override
public void configure() throws Exception {

from(startEndpoint()).to("log:mail");
}

};

try {
camelContext.addRoutes(route);
} catch (Exception e) {
throw new RuntimeException(e);
}

camelContext.start();

Thread.sleep(60 * 1000);
}

private String startEndpoint() {
return "imaps://myserver.mydomain?username=myuser&password=mypassword&sslContextParameters=#sslContextParameters";
}

如果失败并出现以下错误:
Camel (camel-1) thread #0 - imaps://myserver.mydomain, SEND TLSv1 ALERT:  fatal, 

description = certificate_unknown
Camel (camel-1) thread #0 - imaps://myserver.mydomain, WRITE: TLSv1 Alert, length = 2
[Raw write]: length = 7
0000: 15 03 01 00 02 02 2E .......
Camel (camel-1) thread #0 - imaps://myserver.mydomain, called closeSocket()
Camel (camel-1) thread #0 - imaps://myserver.mydomain, handling exception: 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
May 27, 2014 2:23:17 PM com.liferay.portal.kernel.log.Jdk14LogImpl warn
WARNING: Consumer Consumer[imaps://myserver.mydomain?password=xxxxxx&sslContextParameters=%23sslContextParameters&username=myuser] failed polling endpoint: Endpoint[imaps://myserver.mydomain?password=xxxxxx&sslContextParameters=%23sslContextParameters&username=myuser]. Will try again at next poll. Caused by: [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]
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:670)
<snipped>

我试过添加 mail.imaps.ssl.trust URI 的参数。

我可以看到证书未知,但我不明白为什么。我也试过使用标准 javax.net.ssl.trustStore参数也不起作用。

我究竟做错了什么?

最佳答案

I have tried adding mail.imaps.ssl.trust parameter to the URI.



设置 mail.imaps.ssl.trust via Camel 对我也不起作用。我使用的是 Java Mail 1.4.2,不得不发现 mail.imaps.ssl.trust在 1.4.3 ( Changelog ) 中添加了支持。

关于java - 如何使用 Apache Camel + SSL 接收电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23882558/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com