4

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.

1
  • Do you want to get every one's mail or just the specific user's mail? Commented Oct 7, 2018 at 9:05

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

0

To get each one's mail.

var users = graphClient.Users.Request().GetAsync().Result;

To get the specific user's mail:

List<QueryOption> options = new List<QueryOption>
{
     new QueryOption("$filter", "startswith(displayName,'the specific user's mail')")
};
var users= await graphClient.Users.Request(options).GetAsync();
//Or
  var users = await graphClient.Users.Request().Filter("startswith(displayName,'help')").GetAsync();

Get Mail:

  foreach (var item in users)
    {
      string currentMail=item.Mail;
    }

Update 2018-10-7 For your updated post:

You can use the following API to filter the mails:

https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$filter=ReceivedDateTime ge 2018-10-04 and startswith(subject,'{subject}') 

2 Comments

It is normal behavior. Many thing is still not supported in Graph API.
How do you call Web API from graphClient?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.