Ani Menon Ani Menon - 1 month ago 66
Python Question

How to get all mails from MS exchange in Python?

I want to view all the mails I have received on MS Exchange/OWA. Is there a way to do this using Python?

I do see few solutions in C#/Java.

But how may I do it in Python?
A similar question is Connect to exchange with python, but I am not able to understand how to do it.

Answer

There's no tutorial for that, and no Python packages support the inbox, AFAIK.

UPDATE: I went ahead and implemented the inbox in the Python EWS package I maintain (https://pypi.python.org/pypi/exchangelib). Here's a simple example:

from exchangelib import DELEGATE, Account, Credentials

creds = Credentials(
    username='MYWINDOMAIN\myusername', 
    password='topsecret')
account = Account(
    primary_smtp_address='john@example.com',
    credentials=creds, 
    autodiscover=True, 
    access_type=DELEGATE)

for message in account.inbox.all():
    print(message)