1

我想在 Outlook 中使用 Python 脚本执行一项“简单”任务,但我通常使用 PHP,这对我来说有点困难。

这是任务:

  • 打开 Outlook(没关系)
  • 检查特定帐户,例如:test@test.com
  • 打开最后一封邮件

我想在屏幕上打开“真实”消息窗口,而不仅仅是访问内容。可能吗?

4

2 回答 2

1

对于您的第二个要求,该帐户可以是共享收件箱吗?

这是其余的代码:

import win32com.client

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
message = messages.GetLast()
message.display()
于 2013-04-09T14:04:34.053 回答
0

这是python中exchangelib的另一个例子:

https://medium.com/@theamazingexposure/accessing-shared-mailbox-using-exchangelib-python-f020e71a96ab

这是获取最后一封电子邮件的片段。我使用 order by 和根据您的 order by 选择第一个或最后一个的组合来做到这一点:

from exchangelib import Credentials, Account, FileAttachment

credentials = Credentials('FirstName.LastName@Some_Domain.com', 'Your_Password_Here')
account = Account('FirstName.LastName@Some_Domain.com', credentials=credentials, autodiscover=True)
filtered_items = account.inbox.filter(subject__contains='Your Search String Here')
print("Getting latest email for given search string...")
for item in account.inbox.filter(subject__contains='Your Search String Here').order_by('-datetime_received')[:1]:   #here is the order by clause:: you may use order_by('datetime_received')[:-1]
    print(item.subject, item.text_body.encode('UTF-8'), item.sender, item.datetime_received) #item.text_body.encode('UTF-8') gives you the content of email

虽然尝试打开真实消息可能有点挑战,但一旦我有解决方案,我会更新这部分。如果我可能会问:: 你在看一个只有 python 的解决方案吗?

于 2020-06-15T01:59:54.360 回答