Microsoft Outlook client Python package that uses the requests library.
Important
This packages uses pydantic~=1.0!
from a script:
import outlooklib
import pandas as pd
client_id = "123"
client_secret = "123"
tenant_id = "123"
sp_domain = "companygroup.sharepoint.com"
client_email = "[email protected]"
# Initialize Outlook client
outlook = outlooklib.Outlook(client_id=client_id,
tenant_id=tenant_id,
client_secret=client_secret,
sp_domain=sp_domain,
client_email=client_email,
client_folder="Inbox")
# Retrieves a list of mail folders
response = outlook.list_folders()
if response.status_code == 200:
df = pd.DataFrame([item.dict() for item in response.content])
print(df)
# Retrieves the top 100 messages from the specified folder, filtered by a given condition
response = outlook.list_messages(filter="isRead ne true")
if response.status_code == 200:
df = pd.DataFrame([item.dict() for item in response.content])
print(df)
message_id = "A...A=="
response = outlook.download_message_attachment(id=message_id,
path=r"C:\Users\admin",
index=True)
if response.status_code == 200:
print("Attachment(s) downloaded successfully")
# Deletes a message from the current folder
message_id = "A...A=="
response = outlook.delete_message(id=message_id)
if response.status_code == 204:
print("Message deleted successfully")
outlook.change_folder(id="root")
Install python and pip if you have not already.
Then run:
pip install pip --upgrade
For production:
pip install outlooklib
This will install the package and all of it's python dependencies.
If you want to install the project for development:
git clone https://github.com/aghuttun/outlooklib.git
cd outlooklib
pip install -e ".[dev]"
To test the development package: Testing
BSD License (see license file)