0

我正在尝试使用 Camel 配置 Spring Boot,以便能够使用 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 类添加了一个用于创建 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% 清楚

4

1 回答 1

3

您可能会使用 Spring BootSSLContextParameters在其注册表中使用@Bean.

公开方法并添加@Bean注释:

@Bean
public SSLContextParameters myMailSslContextParameters() {

然后使用#查找语法告诉 Camel smtp 端点使用它:

smtps://myhost:465?myuser&password=mypass&debugMode=true&sslContextParameters=#myMailSslContextParameters

请注意方法的名称是您用于查找的名称。

于 2018-01-14T08:57:21.357 回答