Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example of Reading User's Email Using Microsoft Graph

I'm creating a C# .Net Core 2.0 console application to read a specific user's email. I successfully got this sample console application working. So authentication is working. I added permissions to Read all User's email. I looked at the API docs and I can't see examples of reading a user's email. Plenty of send examples. Any help appreciated.

like image 335
user2970483 Avatar asked Sep 17 '25 23:09

user2970483


1 Answers

Thanks for posting. I got this to work if I comment out the Filter:

            GraphServiceClient client = GetAuthenticatedClient();

            string subject = "RE: ACTION NEEDED:";
            string dt = "2018-10-5T00:00:00";
            IUserMessagesCollectionPage msgs = client.Users["[email protected]"].Messages.Request()
                //.Filter($"receivedDateTime ge '{dt}'")  // Invalid filter
                .Filter($"startswith(subject, '{subject}') and receivedDateTime gt {dt}")
                .Select(m => new { m.Subject, m.ReceivedDateTime, m.From, m.Body })
                .Top(100)
                .GetAsync().Result;
            int msgCnt = msgs.Count;

I posted something about getting filter to work. startswith works but the date filter fails.

like image 75
user2970483 Avatar answered Sep 21 '25 14:09

user2970483