Read mails through API Calls

Hi all,

Can you please help me on below topic.

I need to read mails from outlook through api calls.

I have tenant id, client id, secret id.

In my organization we are having 2019 studio only.

By using http request please let me know how to read mails send mails.

Thanks in advance.

Navya

Hi @Navya_Nadakuduti

Already answered

Thanks & Regards,
Nived N

@Navya_Nadakuduti

You can try with below documentation

Hope this may help you

Thanks,
Srini

Hi

Hope the below steps would help you resolve this

— Outlook using the HTTP requests in UiPath:

First, you need to create an Azure AD application and register it in your tenant. To do this, follow the instructions in the Microsoft documentation: Register your app with the Azure AD v2.0 endpoint - Microsoft Graph | Microsoft Learn

Once you have created the Azure AD application, you need to grant it the necessary permissions to access your Outlook mailbox. To do this, follow the instructions in the Microsoft documentation: Limiting application permissions to specific Exchange Online mailboxes - Microsoft Graph | Microsoft Learn

In UiPath, create a new sequence and add an “HTTP Request” activity to it.

First we need to get the access token
For that

  1. Set the following properties for the “HTTP Request” activity:
  • Method: POST
  • Endpoint: https://login.microsoftonline.com/[tenant_id]/oauth2/v2.0/token
  • Headers:
    • Key: Content-Type Value: application/x-www-form-urlencoded
  • Body: Enter the following string in the “Body” property, replacing the placeholders with your own values:
client_id=[client_id]&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default&client_secret=[client_secret]&grant_type=client_credentials

Here, [client_id] is your Azure AD application’s client ID, and [client_secret] is your Azure AD application’s client secret. [tenant_id] is your Azure AD tenant ID.
2. Add a “Deserialize JSON” activity after the “HTTP Request” activity to parse the response into a structured format.
3. In the “Input” property of the “Deserialize JSON” activity, enter the following expression: responseContent.ToString()
4. In the “TypeArgument” property of the “Deserialize JSON” activity, enter the following: System.Collections.Generic.Dictionary(Of String, Object)
5. You can now access the access token by using the expression jsonDict("access_token").ToString(). Save this value to a variable for later use.
6. Use the access token obtained to make requests to the Outlook Graph API,

After getting the access token follow these below steps

  1. Set the following properties for the “HTTP Request” activity:
  • Method: GET
  • Endpoint: https://graph.microsoft.com/v1.0/me/messages
  • Headers:
    • Key: Authorization Value: Bearer [access_token]
    • Key: Content-Type Value: application/jsonHere, [access_token] is the access token obtained by authenticating with the Azure AD application.
  1. Add a “Deserialize JSON” activity after the “HTTP Request” activity to parse the response into a structured format.

  2. In the “Input” property of the “Deserialize JSON” activity, enter the following expression: responseContent.ToString()

  3. In the “TypeArgument” property of the “Deserialize JSON” activity, enter the following: System.Collections.Generic.List(Of Object)

  4. After the “Deserialize JSON” activity, add a “For Each” activity to loop through the list of messages.

  5. In the “Values” property of the “For Each” activity, enter the following expression: jsonListHere, jsonList is the variable containing the list of messages returned by the “Deserialize JSON” activity.

  6. Inside the “For Each” activity, you can access the properties of each message using expressions like item("subject").ToString() or item("body")("content").ToString().

Cheers @Navya_Nadakuduti