Python Outlook 获取来自发件人的所有电子邮件

Try*_*ard 5 python

我正在尝试使用 python 来浏览 Outlook 并获取发件人的所有电子邮件。我已经看过但不知道如何做到这一点。我可以按主题获取电子邮件并返回发件人,但我希望获取所有发件人然后返回主题?这就是我用来按主题获取发件人的方法。

import win32com.client


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

inbox = outlook.GetDefaultFolder(6) # "6" refers to the index of a folder - in this case,
                                    # the inbox. You can change that number to reference
                                    # any other folder
messages = inbox.Items
message = messages("Test 08/18/14")
print(message.sender)
Run Code Online (Sandbox Code Playgroud)

这将返回主题为“Test 08/19/14”的邮件的发件人

我想浏览我的电子邮件并获取来自某个发件人的所有电子邮件主题。

Ger*_*rat 3

您似乎正在寻找SenderEmailAddress属性。

您可以通过以下方式查看特定发件人的消息:

for m in messages:
   if m.SenderEmailAddress == 'some_sender@somewhere.com':
       print(m)
Run Code Online (Sandbox Code Playgroud)