How to send an email with an Inline Attachment to outlook with camel-mail

942 Views Asked by At

Outlook 2016 will not display an Email with a text/html Inline Attachment correctly when sent with camel-mail.

The same email is displayed correctly in other mail clients like apple mail.

I have already tried swapping the content type of the mail itself, as well as the content type of the attachment.

When the content type is set to text/rich the inline attachment will display, but the body of the email ends up as a regular attachment.

If the content type of the email is text/html the body will display correctly, but the attachment ends up as a regular attachment and not inline.

The Processor that adds the attachment:

  String emailContent = emailBody.getContent().toString();

  byte[] emailContentByte = emailContent
          .getBytes("UTF-8");


  // add the file as an attachment to the exchange with a text/html format.
  exchange.getIn().addAttachment("cid:http-email", new DataHandler(
          (DataSource) new ByteArrayDataSource(emailContentByte,
                  "text/html")));

The camel smtp endpoint and headers:

        .setHeader("contentType", constant("text/html"))

        .process(new AttachmentBuilder())

        .to("velocity:{{mail.template}}?encoding=UTF-8")

        //send the exchange to the specified email address.
        .toD("smtp://{{mail.smtp.host}}:{{mail.smtp.port}}"
                + "?from={{mail.smtp.from}}"
                + "&to={{mail.smtp.to}}"
                + "&useInlineAttachments=true")
1

There are 1 best solutions below

0
On

I think the content-type of the whole mail message should be Content-Type: multipart/related.

text/html would be the content-type of the individual message parts.

Perhaps this q/a from stackoverflow helps. It is about images but the main point is the content-type of the surrounding message.