我需要对我的企业outlook帐户进行排序,并希望对通过某个地址发送的所有电子邮件进行排序,并找到该电子邮件的所有回复。我的理解是,我可以使用win32com.client模块访问outlook,并且能够阅读文件夹中所有“未读”的电子邮件。但是,我想更改过滤器,根据特定发件人阅读电子邮件。我似乎找不到一个可以在messages对象上调用的方法的全面列表。你能指定一个发送者吗
以下是我目前的代码:
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
messages.Sort("[ReceivedTime]",True)
sender = 'xxxxx@xxxx.com'
for message in messages:
if sender in message:
print (message.body)
迭代文件夹中的所有项目并不是一个好主意。相反,您需要在Outlook中使用
Items
类的Find/FindNext或Restrict方法。请在以下文章中阅读更多关于它们的信息:例如,可以使用以下搜索条件:
此外,您可能会发现
Application
类的AdvancedSearch方法很有用。在Outlook中使用“AdvancedSearch”方法的主要好处是:AdvancedSearch
方法会在后台自动运行它李>Find
/FindNext
方法可应用于特定的Items
集合(请参阅Outlook中文件夹类的Items
属性)李>IsInstantSearchEnabled
属性)李>Stop
方法停止搜索过程李>相关问题 更多 >
编程相关推荐