apache camel - How to send a Multipart Mail? - Stack Overflow

In our Project we need to send a Multipart Email with an empty text and then attached a xml.The layout

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?

Share Improve this question edited Feb 3 at 10:23 DarkBee 15.5k8 gold badges72 silver badges118 bronze badges asked Jan 31 at 10:47 Ge BraunGe Braun 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The 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());

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745266722a4619501.html

相关推荐

  • apache camel - How to send a Multipart Mail? - Stack Overflow

    In our Project we need to send a Multipart Email with an empty text and then attached a xml.The layout

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信