Spring 集成:SMTP 服务器
Spring Integration: SMTP server
我正在使用 Spring Integration 4.1.2.
在程序流程中,在流程结束时我需要发送一封电子邮件。我正在使用以下内容:
<int:payload-type-router input-channel="response.in">
<int:mapping type="java.lang.String" channel="response.out"/>
<int:mapping type="org.springframework.mail.SimpleMailMessage" channel="mail.out"/>
</int:payload-type-router>
<mail:outbound-channel-adapter channel="mail.out" mail-sender="mailSender"/>
这工作正常。
我也想处理邮件服务器宕机的情况。
我尝试了以下解决方案,但它不起作用。
<int:chain input-channel="errorChannel" output-channel="emailErrorChannel">
<int:transformer ref="errorUnwrapper" />
</int:chain>
和解包器:
@MessageEndpoint
public class ErrorUnwrapper {
@Transformer
public Message<?> transform(final ErrorMessage errorMessage) {
Message<?> failedMessage = ((MessagingException) errorMessage.getPayload()).getFailedMessage();
return failedMessage;
}
}
但这不起作用。我想捕获异常并将有意义的响应发送回用户而不是堆栈跟踪。我想在 Spring 集成中执行此操作。否则我将不得不使用服务激活器而不是 SI mail
扩展名编写 Java 邮件服务调用。
还是单向组件?我刚找到这个 blog post doing the same. I've also read this 但一无所获。
您可能需要将 errorChannel
添加到您开始的任何内容;您需要向我们展示您的其余配置。
或者,您可以添加一个 ExpressionEvaluatingAdvice to the mail adapter; see this sample 作为使用建议的示例。
我正在使用 Spring Integration 4.1.2.
在程序流程中,在流程结束时我需要发送一封电子邮件。我正在使用以下内容:
<int:payload-type-router input-channel="response.in">
<int:mapping type="java.lang.String" channel="response.out"/>
<int:mapping type="org.springframework.mail.SimpleMailMessage" channel="mail.out"/>
</int:payload-type-router>
<mail:outbound-channel-adapter channel="mail.out" mail-sender="mailSender"/>
这工作正常。
我也想处理邮件服务器宕机的情况。
我尝试了以下解决方案,但它不起作用。
<int:chain input-channel="errorChannel" output-channel="emailErrorChannel">
<int:transformer ref="errorUnwrapper" />
</int:chain>
和解包器:
@MessageEndpoint
public class ErrorUnwrapper {
@Transformer
public Message<?> transform(final ErrorMessage errorMessage) {
Message<?> failedMessage = ((MessagingException) errorMessage.getPayload()).getFailedMessage();
return failedMessage;
}
}
但这不起作用。我想捕获异常并将有意义的响应发送回用户而不是堆栈跟踪。我想在 Spring 集成中执行此操作。否则我将不得不使用服务激活器而不是 SI mail
扩展名编写 Java 邮件服务调用。
还是单向组件?我刚找到这个 blog post doing the same. I've also read this 但一无所获。
您可能需要将 errorChannel
添加到您开始的任何内容;您需要向我们展示您的其余配置。
或者,您可以添加一个 ExpressionEvaluatingAdvice to the mail adapter; see this sample 作为使用建议的示例。