How to get ContentBytes for a .msg attachment in an email message

Andrew Earl 105 Reputation points
2024-08-24T16:22:08.6133333+00:00

Hi, we have an application that downloads email attachments using the contentBytes tag returned by https://graph.microsoft.com/v1.0/me/messages/A{{messageId}}/attachments/{{attachmentId}}

This works fine for all attachment types including .eml attachments in Outlook for Mac, apart from .msg attachments in Outlook for Windows where no contentBytes tag is returned.

Is there a way to get contentBytes for .msg attachments?

Thanks

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,866 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Hitesh Pachipulusu - MSFT 1,260 Reputation points Microsoft Vendor
    2024-08-26T11:37:16.0033333+00:00

    Hello Andrew Earl,

    Greetings from Microsoft Support!

    It sounds like you’re encountering an issue with .msg attachments in Outlook for Windows using Graph API. The contentBytes property is not directly available for .msg attachments because they are treated as itemAttachment rather than fileAttachment.

    To retrieve the content of a .msg attachment, you can use the $value segment in your request URL. Here’s how you can do it:

    1. Get the attachment details:
    GET https://graph.microsoft.com/v1.0/me/messages/{messageId}/attachments/{attachmentId}
    
    1. Retrieve the raw content:
    GET https://graph.microsoft.com/v1.0/me/messages/{messageId}/attachments/{attachmentId}/$value
    

    This will return the raw contents of the .msg file. Please check documentation.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.