需要 <int-mail:outbound-channel-adapter> 的任何工作示例; [英] Need any working example of <int-mail:outbound-channel-adapter>
本文介绍了需要 <int-mail:outbound-channel-adapter> 的任何工作示例;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能提供一个工作示例(配置)?
Can anyone provide a working example (config) for ?
我检查了Spring 集成参考手册"和 github,其中提供了所有 si 示例,但我找不到任何关于 .
I checked "Spring Integration Reference Manual" and github where all si samples have been provided but i could not find anything for .
推荐答案
是这样的:
<int:chain input-channel="inputChannel">
<int-mail:header-enricher>
<int-mail:to value="mailto"/>
<int-mail:from value="mailfrom"/>
<int-mail:subject value="With Content Type"/>
<int-mail:content-type value="text/html"/>
</int-mail:header-enricher>
<int-mail:outbound-channel-adapter host="smtp.gmail.com"
port="587"
username="user"
password="password"
java-mail-properties="javaMailProperties"/>
</int:chain>
<util:properties id="javaMailProperties">
<prop key="mail.debug">true</prop>
<prop key="mail.smtps.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
</util:properties>
更新
没错:整个 payload
都转换为电子邮件.当然,在发送之前将payload
转换
到适当的对象是典型的任务.
That's right: the entire payload
is converted to the email. Of course it is typical task to transform
the payload
to appropriate object before sending.
MailSendingMessageHandler
这些类型用于payload
:
if (payload instanceof MimeMessage) {
mailMessage = new MimeMailMessage((MimeMessage) payload);
}
else if (payload instanceof MailMessage) {
mailMessage = (MailMessage) payload;
}
else if (payload instanceof byte[]) {
mailMessage = this.createMailMessageFromByteArrayMessage((Message<byte[]>) message);
}
else if (payload instanceof String) {
String contentType = (String) message.getHeaders().get(MailHeaders.CONTENT_TYPE);
if (StringUtils.hasText(contentType)) {
mailMessage = this.createMailMessageWithContentType((Message<String>) message, contentType);
}
else {
mailMessage = new SimpleMailMessage();
mailMessage.setText((String) payload);
}
}
else {
throw new MessageHandlingException(message, "Unable to create MailMessage from payload type ["
+ message.getPayload().getClass().getName() + "], expected MimeMessage, MailMessage, byte array or String.");
}
这篇关于需要 <int-mail:outbound-channel-adapter> 的任何工作示例;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文