This guide covers how to develop and test pyOutlook functionality.
The quickest way to get an access token for testing is using Microsoft Graph Explorer:
Navigate to Microsoft Graph Explorer
Click Sign in with Microsoft and authenticate with:
- Your personal Microsoft/Outlook account, or
- Your business/organizational account (e.g., name@company.onmicrosoft.com)
- Once signed in, click the Access Token button in the top toolbar
- A dialog will appear showing your current access token
- Click Copy to copy the token to your clipboard
You can now use this token to test pyOutlook functionality:
from pyOutlook import OutlookAccount
# Paste your token here
token = 'eyJ0eXAiOiJKV1QiLCJub25jZSI6...' # Your token from Graph Explorer
# Create account instance
account = OutlookAccount(token)
# Test basic functionality
messages = account.inbox()
print(f'Successfully retrieved {len(messages)} messages')
# Test other features
folders = account.folders.all()
print(f'Found {len(folders)} folders')pip install -r requirements.dev.txt# Run all tests
pytest
# Run with coverage
pytest --cov=src/pyOutlook --cov-report=html
# Run specific test file
pytest tests/test_message.py
# Run with verbose output
pytest -vThe utils/test_services.py script tests all services with a real Outlook account:
# Method 1: Command line argument
python utils/test_services.py "your_access_token"
# Method 2: Environment variable
ACCESS_TOKEN="your_access_token" python utils/test_services.pyThis script tests:
- FolderService (all folders, get specific folder)
- MessageService retrieval (all, inbox, sent, drafts, from_folder, get by ID)
- MessageService sending (simple, with Contact, with CC/BCC, with attachment)
- ContactService (get overrides)
- Contact operations (create and convert to dict)
Note: The script sends 4 test emails to jensaiden@gmail.com when testing sending functionality.
You'll see errors like:
401 UnauthorizedAccess token has expired- Authentication-related error messages