如何从Python中获取MS Exchange的所有邮件?

Ani*_*non 6 python email exchange-server-2010

我想查看我在MS Exchange/OWA上收到的所有邮件.有没有办法用Python做到这一点?

我确实在C#/Java中看到了一些解决方案.

但是我怎么能用Python做呢?类似的问题是使用python连接到交换,但我无法理解如何做到这一点.

Eri*_*and 14

我维护的Python EWS包(https://pypi.python.org/pypi/exchangelib)支持这一点.这是一个简单的例子:

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)

# 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)
Run Code Online (Sandbox Code Playgroud)