我正在尝试使用以下代码同时在 2 个单独的收件箱中侦听 OnItemAdd 事件:
class Handler_Class():
def OnItemAdd(self, mail):
#Check if the item is of the MailItem type
if mail.Class==43:
print(mail.Subject, " - ", mail.Parent.FolderPath)
inboxes = ["inbox1", "inbox2"]
for inbox in inboxes:
items = win32com.client.DispatchEx("Outlook.Application").GetNamespace("MAPI").Folders[inbox].Folders["Inbox"].Items
win32com.client.DispatchWithEvents(items, Handler_Class)
print(datetime.now(),"Ready to pump")
pythoncom.PumpMessages()
pythoncom.PumpMessages() 似乎不起作用。如果我重构代码只收听一个收件箱的项目,它确实有效。
关于如何解决这个问题的任何想法?