Home > Blockchain >  How to filter Email Messages by Subject Body & HasAttachments using C# Graph API
How to filter Email Messages by Subject Body & HasAttachments using C# Graph API

Time:12-09

var inboxMessages = await graphClient.Me
              .MailFolders["Inbox"]
              .Messages
              .Request()
              .Select("sender,subject")
              .Top(5)
              .GetAsync();

I want to filter the messages by subject and hasAttachment using C#

I am seeing few examples like this ,but how we need implement this in C# in above code?

/v1.0/me/messages?$search="subject:search term"
/v1.0/me/messages?$filter=contains(subject, 'my search term')

Can anyone help me out on this.

CodePudding user response:

You can filter messages with attachments based on the subject that contains specific text like this

var subjectText = "your text";
var inboxMessages = await graphClient.Me
            .MailFolders["Inbox"]
            .Messages
            .Request()
            .Select("sender,subject")
            .Filter($"hasAttachments eq true and contains(subject,'{subjectText}')")
            .Top(5)
            .GetAsync();

Documentation:

$filter query operator

  • Related