Python win32com.client 与 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.GetLast()
print(message)
body_content = message.body
print body_content
有没有人知道我可以在哪里找到相关的文档?我想用一个 GetAll() 函数,然后根据主题进行筛选,或者用一个 getSubject() 函数,但我完全找不到相关的文档。任何帮助都会很棒。
1 个回答
3
我发现用谷歌搜索“microsoft interop”可以很快找到相关页面。比如在你的情况下,我搜索了“microsoft interop outlook getdefaultfolder”,这让我找到了MSDN的NameSpaceClass.GetDefaultFolder 方法页面,之后经过几次点击,我又找到了Items Members页面。
我对所有的MS Office应用程序都用同样的搜索方法。