Followed the documentation to send an Attachment with Apache Camel version >= 3.0 here:
https://camel.apache.org/components/3.21.x/others/attachments.html
I have tried to send an Excel, and also a text file using this methodology:
File file = writeToExcel(ots);
AttachmentMessage attMsg = exchange.getIn(AttachmentMessage.class);
attMsg.addAttachment(file.getName(), new DataHandler(new FileDataSource(file)));
Which is called as a Bean in my Blueprint XML file here and tries to send the mail (which works without attachments) to a local SMTP server:
<process ref="WIPExtractor"/>
<!-- Prepare email -->
<setHeader name="subject">
<constant>Excel Report</constant>
</setHeader>
<setHeader name="to">
<constant>[email protected]</constant>
</setHeader>
<setHeader name="from">
<constant>[email protected]</constant>
</setHeader>
<!-- Send the email with the Excel attachment -->
<to uri="smtp://localhost:25"/>
The error when I do not specify a MIMEType:
Caused by: javax.activation.UnsupportedDataTypeException: multipart/mixed;
The error when I add a Content-Type header with multipart/mixed as value:
Caused by: javax.mail.MessagingException: MIME part of type “multipart/mixed; charset=UTF-8” contains object of type javax.mail.util.SharedByteArrayInputStream instead of MimeMultipart