using Microsoft.Graph
IMessageAttachmentsCollectionPage Message.Attachments
I can not seem to get this to take any "ContentBytes" which is in the FileAttachment.ContentBytes.
My sample is from 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"
}
}
};
I'm not quite sure what exactly is going here without seeing a trace of what is being set in the request, an error message, or a http status code. I do know that you can't set the HasAttachments property, that property is only set by the service. Oh, the issue here is that you're setting the Message.Attachments property as a new[] instead of a new MessageAttachmentsCollectionPage. With that said, I just ran the following code and it worked as expected so we know the service will work for this scenario.
I hope this helps and saves you time.
Update: This is using Microsoft.Graph.
Using the sample above from GitHub this is resolved, see below: