Python Outlook 获取发件人所有邮件
我想用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)
这段代码可以返回主题为“Test 08/19/14”的邮件的发件人。
我想要遍历我的邮件,获取某个发件人的所有邮件主题。
1 个回答
3
看起来你是在寻找 SenderEmailAddress 这个属性。
你可以通过以下方式查看某个发件人的消息:
for m in messages:
if m.SenderEmailAddress == 'some_sender@somewhere.com':
print(m)