Python Integration with Microsoft Outlook

Python Integration with Microsoft Outlook: Accessing Emails via the Microsoft Graph API

To access emails via Python using the Microsoft Graph API, you’ll need to follow a few steps. Firstly, you will need to register a new application in the Azure portal to obtain the necessary client ID and client secret. Here’s how you can do it:

Open a new incognito window in Google Chrome.

1. Login to Outlook using the following credentials:

· Email Id: [your email id]

· Password: [your password]

· Access Outlook using this link: https://outlook.office.com/

3. Next, login to the Azure Portal using the same credentials as above:

· Email Id: [your email id]

· Password: [your password]

· Access the Azure Portal using this link: https://portal.azure.com/

4. In the Azure Portal, navigate to the “App registrations” service.

5. Click on “+ New Registration” to create a new registration.

6. Fill in the required fields, including:

· Name: [name of the registration]

· Supported account types: [select the appropriate account types]

· Redirect URI: https://localhost.

7. Click on “Register” to complete the registration process.

 

 

Overview of your registered app should look like this

 

8. Now Open your registered app and proceed with the following configurations:

a. Certificates & secrets:

· Click on “+ New client secret”.

· Fill in the required details for the client secret, including a description.

· Note: Make sure to copy the generated secret value for future reference and store it in a secure location, such as a text editor.

 

 

b. API permissions:

· Click on “+ Add a permission”.

· Select “Microsoft Graph”.

· Choose “Delegated” or “Application” permissions.

· Search for “Mail” and select the relevant permissions you need, such as “Mail.Read” and “Mail.ReadWrite” and give Grant admin.

 

 

 

 

Permission should look like below:

 

 

 

Once you have the Application ID (client ID) and the client secret, you can use them in your Python script to authenticate and access the Microsoft Graph API. Also, ensure that you grant the necessary permissions to your application to access the Outlook mail of other users. This can be done in the “API permissions” section of your application registration in the Azure portal.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *