问题描述
我用骆驼2.9.x对我们目前的项目集成的目的。其中一个途径是由两个端点 - 文件查询终端和SMTP邮件端点。由第一端点产生的文件必须通过SMTP端点作为附件发送。
I'm using Camel 2.9.x for integration purposes in our current project. One of the routes consists of two endpoints - file polling endpoint and smtp mail endpoint. Files produced by the first endpoint must be sent through smtp endpoint as attachments.
有关骆驼的配置我们使用Spring DSL(这其实是一个要求)。 Spring版本3.1.1是。不幸的是,我发现只有Java的DSL的例子和骆驼的路线文件附加到电子邮件中的文档。
For Camel configuration we're using Spring DSL (this actually is a requirement). Spring version is 3.1.1. Unfortunately, I've found only java dsl examples and documentation of attaching a file to a e-mail message in camel routes.
<endpoint uri="file:///path/to" id="file-source"/>
<endpoint uri="smtp://mail.example.com:25/[email protected]&password=secret&[email protected]" id="mail-dest"/>
<route id="simplified-for-readability">
<from ref="file-source"/>
<to ref="mail-dest"/>
</route>
此配置文件发送纯/文身上,而不是作为附件(即使二进制文件)。
有没有一种方法来发送文件作为附件,而不使用Java DSL?
This config sends files as plain/text body, not as attachments (even binary files).Is there a way to send files as attachments without using Java dsl?
推荐答案
这可以用Spring配置完成,但是你可能需要codeA简单的java bean左右,虽然不具有弹簧或做java的DSL。
This could be done with Spring config, but you might have to code a simple java bean or so, although that does not have to do with spring or java DSL.
首先创建一个与此相似的类(你可能需要在这里解决的东西):
First create a class similar to this one (you might need to fix stuff here):
// Note: Content Type - might need treatment!
public class AttachmentAttacher{
public void process(Exchange exchange){
Message in = exchange.getIn();
byte[] file = in.getBody(byte[].class);
String fileId = in.getHeader("CamelFileName",String.class);
in.addAttachment(fileId, new DataHandler(file,"plain/text"));
}
}
然后,只需线了一个Spring bean,并在您的路线中使用它。应该做的伎俩。
Then just wire up a spring bean and use it in your route. Should do the trick.
<bean id="attacher" class="foo.bar.AttachmentAttacher"/>
<route>
<from ref="file-source"/>
<bean ref="attacher"/>
<to ref="mail-dest"/>
</route>
这篇关于如何通过骆驼春天DSL发送文件作为邮件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!