Inline attachment MIME type in Apache Came

1.1k Views Asked by At

I would like to add an image as an Inline attachment and everything works fine using the following code

<img src="cid:logo.jpg">
in.addAttachment("cid:logo.jpg", new DataHandler(new FileDataSource("src/resources/logo.jpg")));

The only problem is that, I can not see the image as an inline attachment in Thunderbird because the content type is "application/octet-stream" but it must be "image/jpeg" in order to be shown correctly. When I add the MIME type in Apache Camel like this:

in.addAttachment("cid:logo.jpg", new DataHandler(new FileDataSource("src/resources/logo.jpg"), "image/jpeg"));

it throws and exception saying that "no object DCH for MIME type image/pjpeg" How can I deal with this problem?!

2

There are 2 best solutions below

0
On

Create a DataSource as described in this JavaMail FAQ entry and use it in place of the FileDataSource in your first example.

2
On

Not sure if this is actually your issue but if you check the docs (http://camel.apache.org/mail.html) it states:

Geronimo mail .jar Icon We have discovered that the geronimo mail .jar (v1.6) has a bug when polling mails with attachments. It cannot correctly identify the Content-Type. So, if you attach a .jpeg file to a mail and you poll it, the Content-Type is resolved as text/plain and not as image/jpeg. For that reason, we have added an org.apache.camel.component.ContentTypeResolver SPI interface which enables you to provide your own implementation and fix this bug by returning the correct Mime type based on the file name. So if the file name ends with jpeg/jpg, you can return image/jpeg. You can set your custom resolver on the MailComponent instance or on the MailEndpoint instance.

If that is your issue, the solution is to provide your own implementation of the ContentTypeResolver