我试图阅读电子邮件,只有特定帐户登录到我的outlook。假设我有帐户1、2、3、4、5&假设它们都有自定义文件夹:文件夹1、文件夹2、文件夹3。我只想从1、3和5帐户中读取文件夹1、2和3中的所有电子邮件。你知道吗
我的代码似乎还可以,但我的问题是,我似乎真的不知道如何选择我想从中读取的帐户,所以我的代码只读取一个默认帐户。我需要知道如何指定从哪个帐户读取。你知道吗
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
folders = ["Folder 1", "Folder 2", "Folder 3"]
for folder in folders:
messages = inbox.Folders(folder).Items
for msg in messages:
print(msg.Subject)
等等。。。你知道吗
//编辑//
为此,我做了以下工作:
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
stores = outlook.Stores # Storing the different outlook profiles
# Loop through each outlook profile
for store in stores:
if "Account 1" in store.DisplayName or "Account 3" in store.DisplayName or "Account 5" in store.DisplayName:
inbox = store.GetDefaultFolder(6) # Get Inbox
folders = ["Folder 1", "Folder 2", "Folder 3"]
for folder in folders:
messages = inbox.Folders(folder).Items
for msg in messages:
print(msg.Subject)
不要调用
Namespace.GetDefaultFolder
,而是循环遍历Namespace.Stores
集合中的存储,并为每个Store
对象调用Store.GetDefaultFolder
。你知道吗相关问题 更多 >
编程相关推荐