Example configuration Microsoft Flow to categorize email subject based on Microsoft Dynamics365

Prerequisites

  • Azure Graph API, with the following permission:

    • Type = Application
    • Permissions = Mail.ReadWrite

 

Introduction

In this guide you will create a Microsoft Flow solution, in which you create a Flow that will set a category on an email based on the contact information in Dynamics365 (in this example Account Relation Status), Learn More

 

Step 1: Create Outlook rule

The Anywhere365 automatically processes a new email as soon as it enters the Inbox. Because of this reason you first need to create an Outlook rule to move the email in a pre-process folder. Below on how to move all email to a folder. Of course you can create your own rules:

  1. Open Outlook (web) client.

  2. Open "Rules, Create New".

  3. Click "Advanced Options...".

  4. Click "Next".

  5. Check "Move it to specified folder".

  6. Select the folder where you want to move it to, for example "Pre-Process".

  7. Click "Finish".

 

Step 2: Create a Microsoft Flow

  1. From your Office Portal, go to your Flow App.

  2. Click "My Flow".

  3. Click "New" and "Create from Blank".

  4. Select connector "Office 365 Outlook, When a new email arrives".

    1. Select the folder you used for the pre-process.

  5. Add the step "Dynamics365, List records":

    1. Organization Name = Connect to your organization tenant

    2. Entity Name = Contacts

    3. Filter Query = emailaddress1 eq '@{triggerBody()?['from']}'

  6. Add the step "Initialize variable":

    1. Name = Company

    2. Type = String

    3. Value:

      first(body('List_records')?['value'])?['_parentcustomerid_value']

  7. Add the step "Dynamics365, Get record".

    1. Organization Name = Connect to your organization tenant

    2. Entity Name = Accounts

    3. Item identifier:

      @{variables('Company')}

  8. Add the step "Initialize variable":

    1. Set "TopScoring" as name.

    2. Set "Sting" as Type.

    3. Set the following Value:

      first(body('Parse_JSON')?['Results']?['output1']?['value']?['Values'])

  9. Add the step "HTTP".

    1. Set "Patch" as method.

    2. Add the following uri:

      https://graph.microsoft.com/v1.0/users/[user id]/messages/[Message id]

    3. Add the following body:

      {

      "Categories": [

      "@{body('Get_record')?['_wsp_relationstatus_label']}"

      ],

      "IsRead": true

      }

    4. Change Authentication to "Active Directory OAuth".

    5. Tenant = Directory (tenant) ID, found in the App Overview

    6. Audience = https://graph.microsoft.com

    7. Client ID = Application (client) ID, found in the App Overview

    8. Credential Type = "Secret"

    9. Secret = Secret, can be created in Azure under "Certificates & Secrets"

  10. Create a new step "Data Operations, Parse JSON".

  11. Create a new step "Office 365 Outlook, Move Email":

    1. Set "Message id" as Message Id.

    2. Set "Inbox" as Folder.