Outlook — Mail, Calendar & Events
Examples for working with Outlook mail, calendar, and events via
Microsoft Graph.
Prerequisites
| Permission |
Description |
Reference |
Mail.ReadWrite (delegated) |
Read, send, and manage messages |
Mail permissions |
Mail.Send (delegated) |
Send mail on behalf of the signed-in user |
Mail permissions |
Calendars.ReadWrite (delegated) |
Create, read, update, delete events and calendars |
Calendar permissions |
MailboxSettings.ReadWrite (delegated) |
Read and update automatic replies, rules |
Mail permissions |
Mail.Read (delegated) |
Read mail tips and message properties |
Mail permissions |
Reports.Read.All (delegated) |
Access email and mailbox usage reports |
Reports permissions |
User.Read.All (delegated or app) |
Read user properties for mailbox audit, shared mailboxes, forwarding detection |
User permissions |
Contacts.ReadWrite (delegated) |
Create, read, update, delete personal contacts |
Contacts permissions |
Place.Read.All (delegated) |
List rooms and room lists |
Places permissions |
Calendars.Read (app) |
Read-only calendar access across tenants |
Calendar permissions |
Quick start
from office365.graph_client import GraphClient
client = GraphClient(tenant="contoso.onmicrosoft.com").with_username_and_password(
"client_id", "user@contoso.com", "password"
)
# Send a quick message
client.me.send_mail(
subject="Hello",
body="This is a test.",
to_recipients=["recipient@contoso.com"],
).execute_query()
Mail — Messages & Folders
| Scenario |
File |
Why it's useful |
| Send a message |
messages/send.py |
Simplest send — recipient, subject, body |
| Send with large attachment |
messages/send_with_large_attachment.py |
Upload session pattern required for files >3 MB |
| Export messages to CSV |
messages/export_folder_csv.py |
Audit or backup — dump folder contents with subject, sender, date, size |
| Export messages to JSON |
messages/export_json.py |
Data pipeline — backup/interchange via export_to(..., format="json") |
| Export attachments |
messages/export_attachments.py |
Backup — download every attachment from a folder |
| Find large messages |
messages/large_messages.py |
Storage management — find oversized messages by size threshold |
| Clean up old messages |
messages/cleanup_old.py |
Retention — dry-run then delete messages older than X days |
| Archive old messages |
messages/archive_old.py |
Retention — move messages older than X to Archive folder |
| Paginate through mail |
messages/pagination.py |
Walk thousands of messages with $top/$skip |
| Message lifecycle |
messages/lifecycle.py |
Reply, forward, move, copy in one flow |
| Folder management |
messages/folders.py |
Create, empty, mark-all-read, permanent delete |
| Inbox rules + categories |
messages/inbox_rules.py |
Automate message handling with rules and categories |
| Mailbox settings (OOF) |
messages/mailbox_settings.py |
Enable scheduled automatic replies (Out of Office) |
| Mail tips |
messages/mail_tips.py |
Pre-flight check — OOF, moderation, size limits |
| Export MIME |
messages/export_mime.py |
Download message as .eml for backup or eDiscovery |
| Email search |
messages/search.py |
Microsoft Search query across mailbox |
Mail — Administration & Reporting
Calendar — Events
Calendar — Administration & Reporting
Official docs