camel-mail: Body ends up as attachment instead of e-mail body in multipart mail.

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

camel-mail: Body ends up as attachment instead of e-mail body in multipart mail.

Andreas A.
I'm trying to send an e-mail with a subject, body and attached file. The subject and attached file works fine. However when I make an attachment, the body of the email ends up as an unnamed attachment in the final mail.

Is this a bug in Camel or do I need to do something to make sure the Camel-body becomes a "bodyPart" and not an attachment?

Example route:

from("direct:sendReportEmailRoute")
        .routeId("sendReportEmailRoute")
        .setProperty("originalBody", body())
        .process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                        Message in = exchange.getIn();
                        FileDataSource file = new javax.activation.FileDataSource("H:\\file.txt");
                        in.addAttachment("report.txt", new DataHandler(file));
                        in.setBody("Hello");
                }
               
        })
        .to("smtp:xxx?to=xxx@xxx.com,andreasasmuss@gmail.com&from=noreply@xxx.dk&subject=Your report")
        .setBody(simple("${property.originalBody}"));
Reply | Threaded
Open this post in threaded view
|

Re: camel-mail: Body ends up as attachment instead of e-mail body in multipart mail.

Claus Ibsen-2
Not sure what Camel version you use, but tell us, and try test with
newer release.

On Wed, Nov 9, 2016 at 10:44 AM, Andreas A. <[hidden email]> wrote:

> I'm trying to send an e-mail with a subject, body and attached file. The
> subject and attached file works fine. However when I make an attachment, the
> body of the email ends up as an unnamed attachment in the final mail.
>
> Is this a bug in Camel or do I need to do something to make sure the
> Camel-body becomes a "bodyPart" and not an attachment?
>
> Example route:
>
> from("direct:sendReportEmailRoute")
>         .routeId("sendReportEmailRoute")
>         .setProperty("originalBody", body())
>         .process(new Processor() {
>
>                 @Override
>                 public void process(Exchange exchange) throws Exception {
>                         Message in = exchange.getIn();
>                         FileDataSource file = new
> javax.activation.FileDataSource("H:\\file.txt");
>                         in.addAttachment("report.txt", new DataHandler(file));
>                         in.setBody("Hello");
>                 }
>
>         })
>
> .to("smtp:xxx?to=[hidden email],[hidden email]&from=[hidden email]&subject=Your
> report")
>         .setBody(simple("${property.originalBody}"));
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-mail-Body-ends-up-as-attachment-instead-of-e-mail-body-in-multipart-mail-tp5789939.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2
Reply | Threaded
Open this post in threaded view
|

Re: camel-mail: Body ends up as attachment instead of e-mail body in multipart mail.

Andreas A.
I'm using 2.17.3. I guess I could try 2.18.0.
Reply | Threaded
Open this post in threaded view
|

Re: camel-mail: Body ends up as attachment instead of e-mail body in multipart mail.

Claus Ibsen-2
Also a good idea can be to look at the existing unit tests of
camel-mail, to see how some of those does it with file attachments.

On Thu, Nov 10, 2016 at 10:18 AM, Andreas A. <[hidden email]> wrote:
> I'm using 2.17.3. I guess I could try 2.18.0.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-mail-Body-ends-up-as-attachment-instead-of-e-mail-body-in-multipart-mail-tp5789939p5789989.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2
Reply | Threaded
Open this post in threaded view
|

Re: camel-mail: Body ends up as attachment instead of e-mail body in multipart mail.

jmaurin
Hello,

we had got the same problem (ie a attachement file as body).

To resolve it, we have 'force' the content type in the header as :

 in.setHeader("contentType", "text/plain");

Best regards,
jmaurin

Camel version :  2.14.1
Reply | Threaded
Open this post in threaded view
|

Re: camel-mail: Body ends up as attachment instead of e-mail body in multipart mail.

AOladipupo
In reply to this post by Andreas A.
you need to set the content type as part of the uri options or in the exchange header (will overite the uri values). See modified section of your code below:


@Override
                public void process(Exchange exchange) throws Exception {
                        Message in = exchange.getIn();
                        FileDataSource file = new javax.activation.FileDataSource("H:\\file.txt");
                        in.addAttachment("report.txt", new DataHandler(file));
                        in.setHeader("contentType", "text/html");
                        in.setBody("Hello");
                }
Reply | Threaded
Open this post in threaded view
|

Re: camel-mail: Body ends up as attachment instead of e-mail body in multipart mail.

Andreas A.
Thanks guys, setting the content type to text/plain did the trick.