admin管理员组文章数量:1418425
In our Project we need to send a Multipart Email with an empty text and then attached a xml. The layout is
... some headers...
Content-Type: multipart/mixed; boundary=XYZ
--XYZ
Content-type: text/plain; charset=UTF-8
--XYZ
Content-type: application/soap+xml; charset=UTF-8
XML
--XYZ--
So we define a route like this
@Override
public void configure() {
from("direct:example")
.process(exchange -> {
exchange.getIn().setHeader("from", "me");
exchange.getIn().setHeader("to", "you");
exchange.getIn().setHeader("subject", "subject");
MimeBodyPart textBodyPart = new MimeBodyPart();
textBodyPart.setText("", "UTF-8");
MimeBodyPart xmlBodyPart = new MimeBodyPart();
xmlBodyPart.setContent("<tag/>", "application/soap+xml; charset=UTF-8");
MimeMultipart multipart = new MimeMultipart(textBodyPart, xmlBodyPart);
exchange.getIn().setBody(multipart);
exchange.getIn().setHeader(Exchange.CONTENT_TYPE, multipart.getContentType());
})
.to("smtp://connectionString");
}
triggering the route leads to Missing start boundary
and debugging shows, that the multipart body is not correctly set/used by camel, because when parsing the mail, the body is empty.
How to setup the multipart mail correctly when working with Apache Camel?
In our Project we need to send a Multipart Email with an empty text and then attached a xml. The layout is
... some headers...
Content-Type: multipart/mixed; boundary=XYZ
--XYZ
Content-type: text/plain; charset=UTF-8
--XYZ
Content-type: application/soap+xml; charset=UTF-8
XML
--XYZ--
So we define a route like this
@Override
public void configure() {
from("direct:example")
.process(exchange -> {
exchange.getIn().setHeader("from", "me");
exchange.getIn().setHeader("to", "you");
exchange.getIn().setHeader("subject", "subject");
MimeBodyPart textBodyPart = new MimeBodyPart();
textBodyPart.setText("", "UTF-8");
MimeBodyPart xmlBodyPart = new MimeBodyPart();
xmlBodyPart.setContent("<tag/>", "application/soap+xml; charset=UTF-8");
MimeMultipart multipart = new MimeMultipart(textBodyPart, xmlBodyPart);
exchange.getIn().setBody(multipart);
exchange.getIn().setHeader(Exchange.CONTENT_TYPE, multipart.getContentType());
})
.to("smtp://connectionString");
}
triggering the route leads to Missing start boundary
and debugging shows, that the multipart body is not correctly set/used by camel, because when parsing the mail, the body is empty.
How to setup the multipart mail correctly when working with Apache Camel?
1 Answer
Reset to default 0The body must be set as a string, so one hast to write the multipart to OutputStream then call .toString() on the stream.
OutputStream outputStream = new FastByteArrayOutputStream();
multipart.writeTo(outputStream);
exchange.getIn().setBody(outputStream.toString());
本文标签: apache camelHow to send a Multipart MailStack Overflow
版权声明:本文标题:apache camel - How to send a Multipart Mail? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745266721a2650646.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论