0
votes

I am trying to search any keyword in Outlook mailbox including body, subject, attachment, etc using Microsoft graph API with C#. For subject and body I am able to apply filter but same way its not working with attachments. See the code below:

graphClient.Me.MailFolders.Inbox.Messages.Request().Expand("attachments") .Filter($"contains(subject, '{subject}')").OrderBy("Subject").Top(30).GetAsync();

I know in the filter I am passing the subject but I am not sure how to search the content in attachment.

Please provide me some suggestions.

1

1 Answers

0
votes

Haven't tested the scene you described. But if you want to search for information in any part of the message (the sender name, subject, message body, or any attachments), you could choose to use the Microsoft Search API in Microsoft Graph to search messages.

The HTTP example here:

POST https://graph.microsoft.com/beta/search/query
Content-Type: application/json

{
  "requests": [
    {
      "entityTypes": [
        "microsoft.graph.message"
      ],
      "query": {
        "query_string": {
          "query": "contoso"
        }
      },
      "from": 0,
      "size": 25
    }
  ]
}

It queries messages in the signed-in user's mailbox that contain the string "contoso".