Search code examples
microsoft-graph-apimicrosoft-graph-mail

Getting wrong contentType from EML attachment


I am using Microsoft Graph to fetch mail and I recently noticed when an email has a .eml attachment, there are two cases:

  1. If the sender attach that email through drugging emails to the composer, the attachment will be an item attachment type. <-- I can handle this case

  2. If the sender attaches a .eml file through clicking "attach file", that attachment will be a type of file attachment. Up to this point, I think it is fine to be a file attachment. But when I try to fetch that attachment, the attachment content type is application/octet-stream which is wrong. Shouldn't it be message/rfc822? With application/octet-stream, I cannot create that attachment from our server.


Solution

  • It isn't wrong, application/octet-stream simply represents a generic/unknown binary file. From RFC 2046 § 4.5.1:

    The "octet-stream" subtype is used to indicate that a body contains arbitrary binary data.

    Your application can make its own determination on how to handle the file. In this case, the .eml is just a text file. You can simply fetch the attachment and treat it as raw text.