Problem with attachment while getting mime content.

RB 5 Reputation points
2023-02-20T13:40:58.6266667+00:00

Hi!

Im getting a mime content using "users/{id}/messages/{id}/$value" and in some cases where attachment exists, im not getting a content, only headers for this attachment.

In the original message in the preview in Outlook, the attachment is visible and correct.

Example:

----boundary_50_09690074-de38-46a2-bd74-acc7340270d8

Content-Type: application/pdf; name="example.PDF"

Content-Transfer-Encoding: base64

Content-Disposition: attachment; filename="example.PDF"

Content-Description: example.PDF

{EMPTY CONTENT}

----boundary_50_09690074-de38-46a2-bd74-acc7340270d8--

Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. RB 5 Reputation points
    2023-02-23T14:53:43.7566667+00:00

    I will definitely try to download attachments this way, but I am curious why when I use this method:

    GET https://graph.microsoft.com/v1.0/me/messages/{id}/$value

    sometimes there is no content (attachment).

    Example when it is ok.

    --_004_AS8PR08MB909483C571FF651316386ECF9EAB9AS8PR08MB9094eurp_
    Content-Type: text/plain; name="eft.txt"
    Content-Description: eft.txt
    Content-Disposition: attachment; filename="eft.txt"; size=195;
    	creation-date="Thu, 23 Feb 2023 14:18:19 GMT";
    	modification-date="Thu, 23 Feb 2023 14:18:23 GMT"
    Content-Transfer-Encoding: base64
    
    WEo1MVotN0U2RUMtSUtMUFQtRUM0NVUNCg0KRTAxV1hGNFdOQkRUVDdXUQ==
    
    --_004_AS8PR08MB909483C571FF651316386ECF9EAB9AS8PR08MB9094eurp_--
    
    1 person found this answer helpful.

  2. Shivam Dhiman 6,081 Reputation points
    2023-02-20T22:56:01.8133333+00:00

    Hi @RB

    This GET /users/{id}/messages/{id}/$value Graph API will give you MIME content of message with header. If you want to get the content of attachment you need to use GET /users/{id | userPrincipalName}/messages/{id}/attachments/{id}/$value this Graph API endpoint. This will give you raw contents of an attachment that is attached to a user message. Please refer to the below sample screenshot.1

    Please refer to this documentation for more details.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote. 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.