Issues with saving specific message as EML file using MIME content Graph API

arabian abu 1 Reputation point

I'm running this API for reading a specific message content and trying to save (export) as a eml file.
in graph explorer.
it works well with graph explorer console by running the above query and copying the output from Response preview and saving in a notepad file (filename.eml) . while opening this file with Mail app (windows 10 native app) , it shows as original mail.

But it did not work with powershell invoke-Restmethod api calling , the result of api call looks bit different and saving it in a notepad file (filename.eml) did not work. The file just opens as txt file not as original email view like above scenario.

Invoke-RestMethod -Headers @{Authorization="Bearer $($request.access_token)"} -Uri $graph -Method Get | Out-File -FilePath C:\Users\AE\Downloads\exportmail1.eml

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

1 answer

Sort by: Most helpful
  1. Glen Scales 4,431 Reputation points

    In your Graph request you missing the $value in the Query string so its just going to return the default properties of the Message so


    should be


    Because $ is a special character in powershell you need to escape it with a `