twc*_*twc 6 c# microsoft-graph-api
using Microsoft.Graph
IMessageAttachmentsCollectionPage Message.Attachments
Run Code Online (Sandbox Code Playgroud)
我似乎无法得到它来获取 FileAttachment.ContentBytes 中的任何“ContentBytes”。
我的示例来自 Microsoft https://github.com/microsoftgraph/aspnet-snippets-sample。
// Create the message.
Message email = new Message
{
Body = new ItemBody
{
Content = Resource.Prop_Body + guid,
ContentType = BodyType.Text,
},
Subject = Resource.Prop_Subject + guid.Substring(0, 8),
ToRecipients = recipients,
HasAttachments = true,
Attachments = new[]
{
new FileAttachment
{
ODataType = "#microsoft.graph.fileAttachment",
ContentBytes = contentBytes,
ContentType = contentType,
ContentId = "testing",
Name = "tesing.png"
}
}
};
Run Code Online (Sandbox Code Playgroud)
使用上面来自 GitHub 的示例解决了这个问题,见下文:
// Create the message with attachment.
byte[] contentBytes = System.IO.File.ReadAllBytes(@"C:\test\test.png");
string contentType = "image/png";
MessageAttachmentsCollectionPage attachments = new MessageAttachmentsCollectionPage();
attachments.Add(new FileAttachment
{
ODataType = "#microsoft.graph.fileAttachment",
ContentBytes = contentBytes,
ContentType = contentType,
ContentId = "testing",
Name = "testing.png"
});
Message email = new Message
{
Body = new ItemBody
{
Content = Resource.Prop_Body + guid,
ContentType = BodyType.Text,
},
Subject = Resource.Prop_Subject + guid.Substring(0, 8),
ToRecipients = recipients,
Attachments = attachments
};
// Send the message.
await graphClient.Me.SendMail(email, true).Request().PostAsync();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10838 次 |
| 最近记录: |