I have some code that monitors an inbox, and outputs the subject line every time a new email is recieved. For reference, I am using Outlook. The issue is that it only monitors my default inbox. Does anyone know how to get it to monitor other inboxes as well?
import win32com.client
import pythoncom
import re
class Handler_Class(object):
def OnNewMailEx(self, receivedItemsIDs):
for ID in receivedItemsIDs.split(","):
mail = outlook.Session.GetItemFromID(ID)
subject = mail.Subject
print(subject)
outlook = win32com.client.DispatchWithEvents("Outlook.Application", Handler_Class)
pythoncom.PumpMessages()
For reference, I have two mailboxes, lets say one is Personal
and the other is Shared
I would like for the script to only monitor new emails in the Shared
inbox, but right now it only does so for my Personal
inbox.
I have tried making the following changes to the outlook
definition in the script to monitor the mailbox. While it didn't throw an error, it simply didn't pick up on any new mail items in that box:
outlook = win32com.client.DispatchWithEvents("Outlook.Application", Handler_Class).GetNamespace("MAPI").Folders.Item("Shared")
Does anyone know how to work around this? Thanks!