dal*_*lin 4 c# microsoft-graph-api
I am trying to receive some .eml attachments from some emails. Based on the documentation from https://learn.microsoft.com/en-us/graph/outlook-get-mime-message I need to use: GET /users/{id}/messages/{id}/attachments/{id}/$value
The problem here is that I don't know how to do this using Microsoft.Graph library in C#. I don't know to append that "$value" to the call. Below I have attached the C# structure that I am currently using to get attachments for a specific email. Any advice could help. Thanks.
return await _graphServiceClient.Me.Messages[emailId].Attachments.Request().GetAsync()
Run Code Online (Sandbox Code Playgroud)
SDK 目前不直接支持此功能。通常,为了将/$value段附加到生成的请求 URL,您可以访问Content请求构建器上的属性。问题是泛型IAttachmentRequestBuilder没有实现这个属性,而只是FileAttachmentRequestBuilder实现了。
因此,要使其与当前的 SDK 一起工作,您需要这样做:
var msgId = "message-id";
var attId = "attachment-id";
var attachmentRequestBuilder = client.Me.Messages[msgId].Attachments[attId];
var fileRequestBuilder = new FileAttachmentRequestBuilder(
attachmentRequestBuilder.RequestUrl, client);
Console.WriteLine($"Request URL: {fileRequestBuilder.Content.Request().RequestUrl}");
var stream = await fileRequestBuilder.Content.Request().GetAsync();
using(var reader = new StreamReader(stream))
{
Console.WriteLine("Attachment contents:");
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
Console.WriteLine(line);
}
}
Run Code Online (Sandbox Code Playgroud)
我已经让 SDK 人员知道了这一点。
| 归档时间: |
|
| 查看次数: |
1373 次 |
| 最近记录: |