I have written a program that successfully uses the Graph API to check a mailbox and retrieve messages. If a message contains a standard attachment (e.g., PDF, Word document) then the code works. I can see in debug that these are considered a "FileAttachment" type. However, if the message contains an attachment that is another email, or a .wav file that is a voicemail message (which seems odd to me) then the program chokes because these attachments are of type ItemAttachment
and the cast fails. The relevant code is this:
var msgTask = GraphClient.Me.MailFolders.Inbox.Messages.Request().Filter(filter).Expand("attachments").GetAsync();
IMailFolderMessagesCollectionPage messages = msgTask.Result;
foreach (Message msg in messages)
{
// ...
foreach (Attachment att in msg.Attachments)
{
FileAttachment attachment = (FileAttachment)att;
MsgFile.Attachments.Add(new System.IO.MemoryStream(attachment.ContentBytes), attachment.Name);
}
}
I've done a bit of searching and I'm finding documentation using REST to get at the data associated with an ItemAttachment
, but I'm not using REST, at least not directly. This is a Windows command line application, and using NuGet I have downloaded the Microsoft.Graph
and Microsoft.Graph.Core
packages. These are the libraries that I'm using everywhere else in my code to authenticate and access Office 365 data.
So, I'm wondering if anyone has any insight about how to use these libraries to access and download ItemAttachment objects. Googling for info about the Graph API is almost always about REST. I have found some sample code using these libraries, but none of it deals with ItemAttachments.