Reputation: 21
I want to get MimeContent for an email using GraphServiceClient in Microsoft. Graph Ver 1.15.
I found we can get the mime content using: HTTP GET /users/{id}/messages/{id}/$value
But how can I translate this on a Request?
There is another way or another NuGet package to get this?
Upvotes: 2
Views: 702
Reputation: 39
With the lastest Microsoft.Graph package (currently in version 5.31.0.0) you can use this :
var graphClient = new GraphServiceClient(/*your authentication details*/);
var stream = await graphClient.Users[/*your account address*/].Messages[/*your message ID*/].Content.GetAsync();
//for a string content :
var mimeString = new StreamReader(stream).ReadToEnd();
//for a parsed representation, use the fantastic MimeKit
var mimeMessage = MimeMessage.Load(messageStream);
Upvotes: 0
Reputation: 28
Workaround to get mime content from message-id
using (HttpClient httpclient = new HttpClient())
{
httpclient.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
Uri requestEndpoint = new Uri("https://graph.microsoft.com/beta/me/messages/{id}/$value");
string mimeResponse = await httpclient.GetStringAsync(requestEndpoint);
byte[] emailData= System.Text.Encoding.UTF8.GetBytes(mimeResponse);
Stream stream = new MemoryStream(emailData);
//upload logic
}
Upvotes: 1