0 votes
by (300 points)
retagged by

In my application user can forward incoming e-mail.
Some of the incoming e-mails have attachments with image/* mediatype and when I try to send them in forward message I receive "Media type is not valid. (Parameter 'mediaType')".

What should I do in this case? Try to change mediatype for incoming emails' attachments?

Why is Rebex supporting it when I receive e-mail but not when I try to send such e-mail?

Applies to: Rebex Secure Mail

1 Answer

+1 vote
by (134k points)

In general, Rebex Mail tries to accept broken input data (such as messages with invalid "image/*" media types), but reject invalid data when constructing new messages.

This might occasionally cause problems in scenarios where new messages are constructed based on incoming messages. However, producing messages with broken content might instead cause problems to receivers.

In this case, changing the media type to a generic one (such as "application/octet-stream") seems to be the best workaround.

Of course, it would be better to fix the software that created messages with "image/*" headers.

by (300 points)
Why application/octet-stream? Wouldn't it be better to fix mediatype to correct one? In this case image/jpeg? I thought application/octet-stream is for binary files.

Or maybe from your experience e-mail clients still handle attachments correctly if they have application/octet-stream as media type?
by (300 points)
I just noticed that there is this constructor:
new Attachment(content, fileName)
and it will handle media type for me - assign application/octet-stream

I was using
new Attachment(content, fileName, mediaType)
where mediaType could be invalid one from incoming e-mail being forwarded
by (134k points)
Of course, if you can reliably detect some media types such as "image/jpeg" or "image/png", correcting them would be great. Use "application/octet-stream" as a default value for those you were unable to detect.

If you do specify a correct media type in "new Attachment(...)" call, some mail apps might treat the attachment differently from "application/octet-stream" - for example, they might show a thumbnail of the image. (Basically, "application/octet-stream" indicates a binary file with unspecified format.)