Search code examples
azureoffice365microsoft-graph-apioffice365apioffice365-apps

How do i fetch only internal messages from O365 using Graph API


I wan't to fetch only messages that are only internal to organization. Right now the way i see is fetch domains first then for each message see if from/sender domain belongs to that message , based on that differentiate.

But this is lengthy process and not a foolproof technique. Is there any GRAPH API query i can use which readily provides this ?


Solution

  • It does not apear that the REST API queries for Office 365 includes this information directly in the messages. From the Version 2.0 And the Beta this is not included in message output.

    However, it looks like you might be able to get it from the REST API via the headers.

    Try the following query:

    https://graph.microsoft.com/beta/me/messages?$select=internetMessageHeaders&$top=1
    

    This takes top one messages and shows you the email header of the message.
    In the header look for X-OriginatorOrg. The value should be the main domain of your organisation.

    Alternatively you can look at the X-MS-Exchange-Organization-MessageDirectionalityheader. If the value here is Originating it should come from inside your own organisation.