title: How to continuously monitor a new mail in outlook and unread mails of a specific folder in python
body: <p>I want to check for a particular sender email and process it automatically wherever it arrives</p>
  
  <p>However, there may be some situation where my outlook was restarted, mean while i received mail from sender and marked as unread</p>
  
  <p>For continuous monitor for a new mail for a specific subject i have found the following code </p>
  
  <pre><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() 
  </code></pre>
  
  <p>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)</p>
  
  <p>Is there any function to check for unread mails to add within handler_class </p>
  
  <p>Or let me know for any alternate procedure</p>