You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Th...@telekom.de on 2019/09/19 11:25:10 UTC

Email to dead letter channel

Hi,

I send an email with formatting, html or rtf and a pdf as attachment.
But in the dead letter file there is only plain text.
How can I save the orginal email in case of exception?

Code so far in configure():

errorHandler(deadLetterChannel(String.format("file://%s", EMAIL_DEADDIRECTORY)).useOriginalMessage());

from(("imap:// ...").routeId("EmailInput")
   .throwException(IllegalArgumentException.class, "test")
   .to("direct:emailin");



AW: Email to dead letter channel

Posted by Th...@telekom.de.
Thank you, Giovanni. This works. 

Maybe you can give me a hint how to deal with the same approach when splitting. 

Pseudocode
errorHandler(deadLetterChannel(String.format("file://dead")).useOriginalMessage());

from (in).split()
  .choice()
      .when (type == 0)
  		.bean(Doing.class)       //throws Ex1
  		.to(Agg)
    .otherwise() 
      .bean(SomethingElse.class)   //throws Ex2
      .to(Agg)
  .endChoice()
  
from(Agg)
  .bean(Check.class)  //throws Ex3
  .to(foo)  

When Exception 1 or 2 is throw the original Message (e.g. a zip) is copied into dead-dir.
But after the aggregation, Exception 3, this info gets lost. 
How to realizes this? What is missing? 

Regards Thomas  

-----Ursprüngliche Nachricht-----
Von: Giovanni Condello <gi...@coderit.it> 
Gesendet: Donnerstag, 19. September 2019 19:05
An: users@camel.apache.org
Betreff: R: Email to dead letter channel

I see, i missed the formatting part and skipped right to the attachments.

In this case, I would try something like was sugggested here: https://stackoverflow.com/questions/56577633/apache-camel-save-email-to-file-eml-using-routes

e.g (tested locally)

public void configure() throws Exception {
  errorHandler(deadLetterChannel("direct:deadletter").useOriginalMessage());

  from("imaps://.....")
    .routeId("EmailInput")
    .throwException(IllegalArgumentException.class, "test")
    .to("direct:emailin");

  from("direct:emailin")
    .log("This will never fire");

  from("direct:deadletter")
    .log("Got an email!")
    .process(ex -> {
      javax.mail.Message mailMessage = ex.getIn(org.apache.camel.component.mail.MailMessage.class).getMessage();
      ex.getMessage().setHeader(Exchange.FILE_NAME, String.format("%s.eml", ex.getExchangeId()));
      try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        mailMessage.writeTo(baos);
        ex.getMessage().setBody(baos.toByteArray());
      }
    })
    .to("file:deadLetter");
}


________________________________
Da: Thomas.Thiele@telekom.de <Th...@telekom.de>
Inviato: giovedì 19 settembre 2019 18:18
A: users@camel.apache.org <us...@camel.apache.org>
Oggetto: AW: Email to dead letter channel

No. The body is not stored as it come. But text only. Without formatting (e.g. RTF).
I simply want to backup the original Email as eml in case of error.

-----Ursprüngliche Nachricht-----
Von: Condello, Giovanni <g....@techgap.it>
Gesendet: Donnerstag, 19. September 2019 15:47
An: users@camel.apache.org
Betreff: Re: Email to dead letter channel

Hi,

My guess is that the file component doesn't support the attachments API (as noted here:
https://camel.apache.org/components/latest/mail-component.html#_sending_mail_with_attachment_sample
).

One trick could be to route your deadLetterChannel to a direct route, and from there use:
1. the file component to store the body on disk (as you are doing right now) 2. the splitter EIP to iterate over the attachments using the
SplitAttachmentsExpression(true) (
https://camel.apache.org/components/latest/mail-component.html#_how_to_split_a_mail_message_with_attachments)
and then store them on disk as well by setting the appropriate file component headers using the CamelSplitAttachmentId exchange header to recover the attachment name.

Giovanni

Il giorno gio 19 set 2019 alle ore 13:25 <Th...@telekom.de> ha
scritto:

> Hi,
>
> I send an email with formatting, html or rtf and a pdf as attachment.
> But in the dead letter file there is only plain text.
> How can I save the orginal email in case of exception?
>
> Code so far in configure():
>
> errorHandler(deadLetterChannel(String.format("file://%s",
> EMAIL_DEADDIRECTORY)).useOriginalMessage());
>
> from(("imap:// ...").routeId("EmailInput")
>    .throwException(IllegalArgumentException.class, "test")
>    .to("direct:emailin");
>
>
>

R: Email to dead letter channel

Posted by Giovanni Condello <gi...@coderit.it>.
I see, i missed the formatting part and skipped right to the attachments.

In this case, I would try something like was sugggested here: https://stackoverflow.com/questions/56577633/apache-camel-save-email-to-file-eml-using-routes

e.g (tested locally)

public void configure() throws Exception {
  errorHandler(deadLetterChannel("direct:deadletter").useOriginalMessage());

  from("imaps://.....")
    .routeId("EmailInput")
    .throwException(IllegalArgumentException.class, "test")
    .to("direct:emailin");

  from("direct:emailin")
    .log("This will never fire");

  from("direct:deadletter")
    .log("Got an email!")
    .process(ex -> {
      javax.mail.Message mailMessage = ex.getIn(org.apache.camel.component.mail.MailMessage.class).getMessage();
      ex.getMessage().setHeader(Exchange.FILE_NAME, String.format("%s.eml", ex.getExchangeId()));
      try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        mailMessage.writeTo(baos);
        ex.getMessage().setBody(baos.toByteArray());
      }
    })
    .to("file:deadLetter");
}


________________________________
Da: Thomas.Thiele@telekom.de <Th...@telekom.de>
Inviato: giovedì 19 settembre 2019 18:18
A: users@camel.apache.org <us...@camel.apache.org>
Oggetto: AW: Email to dead letter channel

No. The body is not stored as it come. But text only. Without formatting (e.g. RTF).
I simply want to backup the original Email as eml in case of error.

-----Ursprüngliche Nachricht-----
Von: Condello, Giovanni <g....@techgap.it>
Gesendet: Donnerstag, 19. September 2019 15:47
An: users@camel.apache.org
Betreff: Re: Email to dead letter channel

Hi,

My guess is that the file component doesn't support the attachments API (as noted here:
https://camel.apache.org/components/latest/mail-component.html#_sending_mail_with_attachment_sample
).

One trick could be to route your deadLetterChannel to a direct route, and from there use:
1. the file component to store the body on disk (as you are doing right now) 2. the splitter EIP to iterate over the attachments using the
SplitAttachmentsExpression(true) (
https://camel.apache.org/components/latest/mail-component.html#_how_to_split_a_mail_message_with_attachments)
and then store them on disk as well by setting the appropriate file component headers using the CamelSplitAttachmentId exchange header to recover the attachment name.

Giovanni

Il giorno gio 19 set 2019 alle ore 13:25 <Th...@telekom.de> ha
scritto:

> Hi,
>
> I send an email with formatting, html or rtf and a pdf as attachment.
> But in the dead letter file there is only plain text.
> How can I save the orginal email in case of exception?
>
> Code so far in configure():
>
> errorHandler(deadLetterChannel(String.format("file://%s",
> EMAIL_DEADDIRECTORY)).useOriginalMessage());
>
> from(("imap:// ...").routeId("EmailInput")
>    .throwException(IllegalArgumentException.class, "test")
>    .to("direct:emailin");
>
>
>

AW: Email to dead letter channel

Posted by Th...@telekom.de.
No. The body is not stored as it come. But text only. Without formatting (e.g. RTF).
I simply want to backup the original Email as eml in case of error. 

-----Ursprüngliche Nachricht-----
Von: Condello, Giovanni <g....@techgap.it> 
Gesendet: Donnerstag, 19. September 2019 15:47
An: users@camel.apache.org
Betreff: Re: Email to dead letter channel

Hi,

My guess is that the file component doesn't support the attachments API (as noted here:
https://camel.apache.org/components/latest/mail-component.html#_sending_mail_with_attachment_sample
).

One trick could be to route your deadLetterChannel to a direct route, and from there use:
1. the file component to store the body on disk (as you are doing right now) 2. the splitter EIP to iterate over the attachments using the
SplitAttachmentsExpression(true) (
https://camel.apache.org/components/latest/mail-component.html#_how_to_split_a_mail_message_with_attachments)
and then store them on disk as well by setting the appropriate file component headers using the CamelSplitAttachmentId exchange header to recover the attachment name.

Giovanni

Il giorno gio 19 set 2019 alle ore 13:25 <Th...@telekom.de> ha
scritto:

> Hi,
>
> I send an email with formatting, html or rtf and a pdf as attachment.
> But in the dead letter file there is only plain text.
> How can I save the orginal email in case of exception?
>
> Code so far in configure():
>
> errorHandler(deadLetterChannel(String.format("file://%s",
> EMAIL_DEADDIRECTORY)).useOriginalMessage());
>
> from(("imap:// ...").routeId("EmailInput")
>    .throwException(IllegalArgumentException.class, "test")
>    .to("direct:emailin");
>
>
>

Re: Email to dead letter channel

Posted by "Condello, Giovanni" <g....@techgap.it>.
Hi,

My guess is that the file component doesn't support the attachments API (as
noted here:
https://camel.apache.org/components/latest/mail-component.html#_sending_mail_with_attachment_sample
).

One trick could be to route your deadLetterChannel to a direct route, and
from there use:
1. the file component to store the body on disk (as you are doing right now)
2. the splitter EIP to iterate over the attachments using the
SplitAttachmentsExpression(true) (
https://camel.apache.org/components/latest/mail-component.html#_how_to_split_a_mail_message_with_attachments)
and then store them on disk as well by setting the appropriate file
component headers using the CamelSplitAttachmentId exchange header to
recover the attachment name.

Giovanni

Il giorno gio 19 set 2019 alle ore 13:25 <Th...@telekom.de> ha
scritto:

> Hi,
>
> I send an email with formatting, html or rtf and a pdf as attachment.
> But in the dead letter file there is only plain text.
> How can I save the orginal email in case of exception?
>
> Code so far in configure():
>
> errorHandler(deadLetterChannel(String.format("file://%s",
> EMAIL_DEADDIRECTORY)).useOriginalMessage());
>
> from(("imap:// ...").routeId("EmailInput")
>    .throwException(IllegalArgumentException.class, "test")
>    .to("direct:emailin");
>
>
>