This project integrates with the Microsoft Graph API to manage webhooks, receive notifications, and interact with Microsoft 365 emails.
I n this project, we're creating a API to receive user recent email messages informations within a outlook folder
python3 -m venv venv
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
pip install -r requirements.txt
Create an account on the Azure Portal.
Go to "Azure Active Directory" > "App registrations" > "New registration."
After creating the application, note the Application (client) ID and Directory (tenant) ID.
Create a client secret and note the generated value.
Create a '.env' file in the project root with following information:
AZURE_CLIENT_ID=your_client_id
AZURE_TENANT_ID=your_tenant_id
AZURE_CLIENT_SECRET=your_client_secret
Use Flask and ngrok to test all methods after deploying it!:
note the : after you create a webhook, the route needs to be "online" and the route also needs to respond with a 200 OK with the validationToken
Flask-Route:
app.route("/webhook", methods=["GET", "POST"])
def webhook():
if request.method == 'POST'
validationToken = request.args.get('validationToken')
if validationToken : return Response(validationToken, status=200, mimetype='text/plain')
Microsoft demands the user to get the access_token to use its methods:
First_one : get the User_token
Check : python src/get_token.py
Webhook code : python scr/webhook.py