Summary:
This blog demonstrates the steps involved to access Microsoft
Outlook email using Outlook Version 2.0 API's.
Use Case:
If you are a application developer then often there might be
at times requirement to read email messages or the email attachments send to a particular account user. So, how could you achieve this? There are
many approaches for this but the most simple one is to make use of Microsoft's Outlook Version
2.0 API's.
Assumption:
1. Office 365 or School or outlook account is a must.
Let's begin the demonstration...
First of all in order to access emails via API's we must
register application on azure portal and then provide appropriate access for
the application/ client and then access emails using REST API's.
App registration on Azure portal
Step 1: Login to azure portal (link)
Step 2: Click on "Portal" as shown below
Step 3: On search bar, search for "App
registrations" as shown below
Step 4: Click on "New registration" button
Step 5: Fill the Application registration form as shown below
Redirect URI is optional here and the URL must be unique to
the environment from where the API's are being called from.
Example: Callback URL for postman client is https://app.getpostman.com/oauth2/callback
Click on "Register" button once done.
NOTE:
1. For School or Office 365 accounts use account type as option 1.
2. For outlook personal account select account type as option 2.
Step 6: Note down the Application or Client ID from the
Overview page
Step 7: Click on "Certificates & secrets"
Step 8: Click on "New client secret"
Step 9: Fill the form as per your requirement
Click on "Add" button
Step 10: Copy the secret generated as this will be only
visible at the time of creation of secret
Step 11: Click on "API permission" from the menu
and then click on "Add a permission" button
Step 12: Click on "Microsoft Graph" ->
"Delegated permissions" -> select "email" ->
"Add permissions"
We are done with the "App registration" on Azure.
Testing Outlook API's using POSTMAN:
Step 1: I'll use API to list all the folders in my outlook
email account as shown below
Method: GET
URL: https://outlook.office.com/api/v2.0/me/MailFolders
Authorization Type: OAuth 2.0
Click on "Get New Access Token"
Step 2: Fill the details relevant to your Azure app created in above steps in the OAuth 2.0 form
Click on "Request Token" -> sign in with your outlook account in next screen
Click on "Use Token"
Step 3: Click on "Send" button
Hope this blog helped you with the procedure to register app on Azure and consume outlook API's. .
Let me know in comments section for any queries.
Know Yourself Blogs...