How to filter by 'from' email using Graph SDK in version 5.0.0

Christopher Sykes 45 Reputation points
2023-03-03T23:10:05.15+00:00

I'm using version 5.0.0 of the Microsoft.Graph package in my .NET 7 app, and trying to make a call using the Graph SDK that returns all emails for a specific user that are from a specific 'from' email. I'm struggling with the filter syntax required to do this. I keep getting a "Microsoft.Graph.Models.ODataErrors.ODataError". Removing the filter line returns the last 20 emails correclty.

The applicantEmail above is a string that looks like your typical email. Ex: ******@domain.com.

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 46,376 Reputation points
    2023-03-06T09:14:54.36+00:00

    Hi @Christopher Sykes

    You want to filter mail by sender, right? Please refer to my sample code:

    var graphClient = new GraphServiceClient(requestAdapter); 
    
    var result = await graphClient.Me.Messages.GetAsync((requestConfiguration) =>
    
    {
    
        requestConfiguration.QueryParameters.Select = new string[] { "id", "subject", "from", "sender" };
    
        requestConfiguration.QueryParameters.Filter = "startswith(from/emailAddress/address,'******@domain.com')";
    
        requestConfiguration.QueryParameters.Count = true;
    
    });
    
    Console.WriteLine("messages:" + JsonConvert.SerializeObject(result));
    
    

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.