This project is an Azure Function that interacts with the Microsoft Graph API to download attachments from emails in an Outlook email account.
azure-function-graph-api
├── HttpTrigger
│ ├── __init__.py
│ ├── function.json
│ └── requirements.txt
├── shared_code
│ ├── graph_api.py
│ └── __init__.py
├── local.settings.json
└── README.md
- Python 3.6 or later
- Azure Functions Core Tools
- An Azure account with an active subscription
- Microsoft Graph API permissions to access emails and attachments
-
Clone the repository:
git clone <repository-url> cd azure-function-graph-api
-
Install dependencies: Navigate to the
HttpTrigger
directory and install the required packages:cd HttpTrigger pip install -r requirements.txt
-
Configure local.settings.json: Update the
local.settings.json
file with your Azure Function settings and Microsoft Graph API credentials. -
Run the Azure Function locally: Use the Azure Functions Core Tools to run the function:
func start
To trigger the function, send an HTTP request to the endpoint provided in the console after running the function locally. The request should include the necessary parameters to specify which email and attachments to download.
- The
shared_code/graph_api.py
file contains the logic for interacting with the Microsoft Graph API. - The
HttpTrigger/__init__.py
file contains the main function that handles incoming HTTP requests and processes them accordingly.
The project includes unit tests for the graph_api.py
module, located in the tests
folder. These tests ensure the functionality of the following methods:
-
authenticate_graph_api
:- Tests successful authentication with the Microsoft Graph API.
- Tests failure scenarios with appropriate error handling.
-
get_email_attachments
:- Tests successful retrieval of email attachments from a specified email.
- Tests failure scenarios when the API call fails.
-
download_attachment
:- Tests successful downloading of an email attachment.
- Tests failure scenarios when the API call fails.
To run the tests, use the following command from the root directory of the project:
python -m unittest discover -s tests
This will discover and execute all the test cases in the tests
folder.
This project is licensed under the MIT License. See the LICENSE file for more details.