I want to check for a particular sender email and process it automatically wherever it arrives
However, there may be some situation where my outlook was restarted, mean while i received mail from sender and marked as unread
For continuous monitor for a new mail for a specific subject i have found the following code
import win32com.client
import pythoncom
import re
class Handler_Class(object):
def OnNewMailEx(self, receivedItemsIDs):
# RecrivedItemIDs is a collection of mail IDs separated by a ",".
# You know, sometimes more than 1 mail is received at the same moment.
for ID in receivedItemsIDs.split(","):
mail = outlook.Session.GetItemFromID(ID)
subject = mail.Subject
print subject
try:
command = re.search(r"%(.*?)%", subject).group(1)
print command # Or whatever code you wish to execute.
except:
pass
outlook = win32com.client.DispatchWithEvents("Outlook.Application",Handler_Class)
#and then an infinit loop that waits from events.
pythoncom.PumpMessages()
Even i want to go through all the unread mails to check whether a mail from a sender has came and process it( if found)
Is there any function to check for unread mails to add within handler_class
Or let me know for any alternate procedure
pythoncom.PumpMessages()
– Corporation