Search mail with Graph API using filter Email and Subject

ASM Automation 0 Reputation points
2023-05-15T14:21:53.5866667+00:00

Hi All,

I am trying to search a mailbox by passing email ID and subject but unable to get the proper URL, can somebody please help here with the proper URL

Microsoft Graph Explorer API
Microsoft Graph Mail API
Microsoft Graph Mail API
A Microsoft API that supports accessing data in users' primary mailboxes and in shared mailboxes.
800 questions
Microsoft Graph SDK
Microsoft Graph SDK
A Microsoft software developer kit designed to simplify building high-quality, efficient, and resilient applications that access Microsoft Graph.
884 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Glen Scales 4,091 Reputation points MVP
    2023-05-16T00:35:22.31+00:00

    I am trying to search a mailbox by passing email ID and subject

    Depends which Email Id are you trying to search with ? the only Id that would be searchable is the internetmessageId if you have the GraphId/itemid you don't need to search just try a get using the identifier.

    To search using the internetmessageId you can use

    https://graph.microsoft.com/v1.0/me/messages?$filter=internetMessageId eq '<12340@blah1234.onmicrosoft.com>'
    
    

    There's actually 3 different ways of searching for messages a Filter, Search and the Graph Search endpoint so for Subject you can use either a KQL query

    https://graph.microsoft.com/v1.0/me/messages?$search="subject:\"Fwd: Subject string to search\""
    

    or and exact filter match

    https://graph.microsoft.com/v1.0/me/messages?$filter=subject eq 'Subject to search'
    

    or startswith

    https://graph.microsoft.com/v1.0/me/messages?$filter=startsWith(subject,'test')
    

    or you can also use the search API https://learn.microsoft.com/en-us/graph/search-concept-messages

    1 person found this answer helpful.

  2. CarlZhao-MSFT 23,361 Reputation points
    2023-05-19T02:29:46.7833333+00:00

    Hi @ASM Automation

    Yes, you can filter messages by date, subject and sender.

    Example:

    https://graph.microsoft.com/v1.0/me/messages?$filter=subject eq '{subject}' and sender/emailAddress/address eq '{sender email address}' and sentDateTime ge 2023-05-17T07:28:08Z
    

    User's image

    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.