I'm trying to send mail attachments together with alternative body text with 
the following piece of code. Having the receiving mail client configured for 
HTML body, all is working as desired: mail text and attachment is displayed 
correctly in the mail client (Outlook, Thunderbird).
But when I switch to plain text only, the attachment is not displayed / 
downloadable - it seems to be "swallowed" by the email clients. Is that normal 
behavior ? How should the message look like that the attachment is visible in 
both cases ? Any help very much appreciated.
I'm trying to send mail attachments together with alternative body text with 
the following piece of code. Having the receiving mail client configured for 
HTML body, all is working as desired: mail text and attachment is displayed 
correctly in the mail client (Outlook, Thunderbird).
But when I switch to plain text only, the attachment is not displayed / 
downloadable - it seems to be "swallowed" by the email clients. Is that normal 
behavior ? How should the message look like that the attachment is visible in 
both cases ? Any help very much appreciated.

@Component
public class MyRouteBuilder3 extends RouteBuilder {
  /*****************************************************************************
   * Camel (3.4.0)
   * @throws Exception
   ****************************************************************************/
  @Override
  public void configure() throws Exception
  {
    from( "direct:mail" )
      .doTry()
        .setBody( constant( new Invoice( "111111", "9999999999", "13.03.2020")))

        .setHeader( "copyOfBody", simple( "${body}" ))
        .to( "velocity://templates/template_txt.vm?encoding=utf-8" )
        .setHeader( "plaintext", simple( "${body}" ))

        .setBody( simple( "${header.copyOfBody}" ))
        .to( "velocity://templates/template_html.vm?encoding=utf-8" )

        .setHeader( "contentType",   constant( "text/html;charset=UTF-8" ))
        .setHeader( "subject",       simple( "Your invoice" ))
        .setHeader( "from",          simple( "sender@localhost.localdomain" ))
        .setHeader( "to",            simple( "receiver@localhost.localdomain" ))

        .process( exchange ->
        {
          AttachmentMessage attMsg = exchange.getIn( AttachmentMessage.class );
          attMsg.addAttachment( "invoice.pdf",
            new DataHandler( new FileDataSource( new File( 
"C:/tmp/invoice.pdf"))));
        })

        .to( 
"smtp://127.0.0.1:25?debugMode=true&alternativeBodyHeader=plaintext" )
    ;
  }
}


Mit freundlichen Grüßen / Kind regards

Jürgen Dorfschmid
Dipl.-Ing.(FH), Software-Entwicklung

Tel.: +49 (7022) 2790 376
Fax: +49 (7022) 2790 499
juergen.dorfsch...@buerotex.de
www.buerotex.de

--------------------------------------------------------------------------------

BÜROTEX metadok GmbH, Max-Eyth-Str. 21, D-72622 Nürtingen
Geschäftsführung: Werner Führer, Thomas Griesinger
Handelsregisternummer: Amtsgericht Stuttgart, HRB 225678

--------------------------------------------------------------------------------

Diese E-Mail enthält vertrauliche oder rechtlich geschützte Informationen. Wenn 
Sie nicht der beabsichtigte Empfänger sind, informieren Sie bitte sofort den 
Absender und löschen Sie diese E-Mail. Das unbefugte Kopieren dieser E-Mail 
oder die unbefugte Weitergabe der enthaltenen Informationen ist nicht gestattet.

Mit freundlichen Grüßen / Kind regards

Jürgen Dorfschmid
Dipl.-Ing.(FH), Software-Entwicklung

Tel.: +49 (7022) 2790 376
Fax: +49 (7022) 2790 499
juergen.dorfsch...@buerotex.de
www.buerotex.de

--------------------------------------------------------------------------------

BÜROTEX metadok GmbH, Max-Eyth-Str. 21, D-72622 Nürtingen
Geschäftsführung: Werner Führer, Thomas Griesinger
Handelsregisternummer: Amtsgericht Stuttgart, HRB 225678

--------------------------------------------------------------------------------

Diese E-Mail enthält vertrauliche oder rechtlich geschützte Informationen. Wenn 
Sie nicht der beabsichtigte Empfänger sind, informieren Sie bitte sofort den 
Absender und löschen Sie diese E-Mail. Das unbefugte Kopieren dieser E-Mail 
oder die unbefugte Weitergabe der enthaltenen Informationen ist nicht gestattet.

Reply via email to