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

时间:2016-04-22 12:56:07

标签: python email exchange-server-2010

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

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

但我怎么能用Python做呢? 类似的问题是Connect to exchange with python,但我无法理解如何做到这一点。

1 个答案:

答案 0 :(得分: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)