Search mail with Graph API using filter Email and Subject

ASM Automation 20 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
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,587 questions
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 36,896 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.


1 additional answer

Sort by: Most helpful
  1. Glen Scales 4,431 Reputation points
    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.