I am trying to listen for the OnItemAdd event in 2 separate inboxes at the same time with the following code:
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()
The pythoncom.PumpMessages() doesn't seem to work though. if I refactor the code to only listen for one inbox's items, it does work.
Any ideas on how to solve this?