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.thi...@telekom.de <thomas.thi...@telekom.de> Inviato: giovedì 19 settembre 2019 18:18 A: users@camel.apache.org <users@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.conde...@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 <thomas.thi...@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"); > > >