Spring 引导和 Camel 邮件 SSL 配置
Spring Boot and Camel Mail SSL config
我正在尝试配置 Spring 使用 Camel 启动,以便能够使用 smtps 发送邮件。
我有简单的路线
@Component
public class EmailRoute extends RouteBuilder {
public static final String IN = "seda://email";
public static final String OUT = "smtps://myhost:465?myuser&password=mypass&debugMode=true";
@Override
public void configure() throws Exception {
from(IN).to(OUT);
}
当我使用这条路线发送东西时出现错误:
javax.mail.MessagingException: Could not connect to SMTP host : myhost
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
我有 pem 文件证书(没有密钥,只有证书)并且我已经将它导入到 jks 钥匙串文件
向 EmailRoute 添加了一个方法 class 用于创建 SSLContextParameters 参数
private SSLContextParameters sslContextParameters(){
KeyStoreParameters store = new KeyStoreParameters();
store.setResource("pathToJskFile/cert.jks");
store.setPassword("123456");
TrustManagersParameters trust = new TrustManagersParameters();
trust.setKeyStore(store);
SSLContextParameters parameters = new SSLContextParameters();
parameters.setTrustManagers(trust);
return parameters;
}
现在不确定如何使用 camel 和 spring boot 连接两个,例如来自 http://camel.apache.org/mail.html 的注册表不是 100% 清楚
您可能可以使用 Spring 引导在其注册表中将 SSLContextParameters
注册到 @Bean
。
创建方法 public 并添加 @Bean
注释:
@Bean
public SSLContextParameters myMailSslContextParameters() {
然后告诉 Camel smtp 端点使用 #
查找语法来使用它:
smtps://myhost:465?myuser&password=mypass&debugMode=true&sslContextParameters=#myMailSslContextParameters
注意方法的名称是您用于查找的名称。
我正在尝试配置 Spring 使用 Camel 启动,以便能够使用 smtps 发送邮件。 我有简单的路线
@Component
public class EmailRoute extends RouteBuilder {
public static final String IN = "seda://email";
public static final String OUT = "smtps://myhost:465?myuser&password=mypass&debugMode=true";
@Override
public void configure() throws Exception {
from(IN).to(OUT);
}
当我使用这条路线发送东西时出现错误:
javax.mail.MessagingException: Could not connect to SMTP host : myhost
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
我有 pem 文件证书(没有密钥,只有证书)并且我已经将它导入到 jks 钥匙串文件
向 EmailRoute 添加了一个方法 class 用于创建 SSLContextParameters 参数
private SSLContextParameters sslContextParameters(){
KeyStoreParameters store = new KeyStoreParameters();
store.setResource("pathToJskFile/cert.jks");
store.setPassword("123456");
TrustManagersParameters trust = new TrustManagersParameters();
trust.setKeyStore(store);
SSLContextParameters parameters = new SSLContextParameters();
parameters.setTrustManagers(trust);
return parameters;
}
现在不确定如何使用 camel 和 spring boot 连接两个,例如来自 http://camel.apache.org/mail.html 的注册表不是 100% 清楚
您可能可以使用 Spring 引导在其注册表中将 SSLContextParameters
注册到 @Bean
。
创建方法 public 并添加 @Bean
注释:
@Bean
public SSLContextParameters myMailSslContextParameters() {
然后告诉 Camel smtp 端点使用 #
查找语法来使用它:
smtps://myhost:465?myuser&password=mypass&debugMode=true&sslContextParameters=#myMailSslContextParameters
注意方法的名称是您用于查找的名称。