从Microsoft Exchange读取电子邮件和下载附件

2024-04-25 23:20:35 发布

您现在位置:Python中文网/ 问答频道 /正文

connect-to-exchange-mailbox-with-python/3072491….我推荐了以下链接,以连接到Exchange Online并在windows上下载附件和阅读邮件(使用Python和exchangelib库)。现在我想在CentOS上完成同样的任务,但是当我手动下载并安装exchangelib库时。 每当我尝试导入exchangelib时,它都会抛出如下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "exchangelib/__init__.py", line 2, in <module>
    from .account import Account  # noqa
  File "exchangelib/account.py", line 8, in <module>
    from cached_property import threaded_cached_property
ImportError: No module named cached_property

有什么问题吗?

我的主要目标是阅读和下载电子邮件。没有可用的imap/pop3服务器地址。除了exchangelib还有别的选择吗?

from exchangelib import DELEGATE, Account, Credentials

credentials = Credentials(
    username='MYWINDOMAIN\\myusername', 
    password='topsecret'
)
account = Account(
    primary_smtp_address='john@example.com', 
    credentials=credentials, 
    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)

我在Windows中使用过这个代码。帮我学Linux。


Tags: infrompyimportlineaccountpropertyitem