How to get all mails from MS exchange in Python?
Asked Answered
M

1

7

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.

Massengale answered 22/4, 2016 at 12:56 Comment(3)
Did you find out a solution for this?Sieve
@ebertbm not a complete solution. You got one?Massengale
I'm still looking for one.Sieve
I
17

The Python EWS package I maintain (https://pypi.python.org/pypi/exchangelib) supports this. Here's a simple example:

from exchangelib import DELEGATE, Account, Credentials

creds = Credentials(
    username='MYWINDOMAIN\myusername', 
    password='topsecret')
account = Account(
    primary_smtp_address='[email protected]',
    credentials=creds, 
    autodiscover=True, 
    access_type=DELEGATE)

# Print first 100 inbox messages in reverse order
for item in account.inbox.all().order_by('-datetime_received')[:100]:
    print(item.subject, item.body, item.attachments)
Incus answered 21/6, 2016 at 19:56 Comment(2)
whyn't it's working for me, throwing error in account object creation.Gust
There’s no way to tell without the error message or stack trace.Incus

© 2022 - 2024 — McMap. All rights reserved.