简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM