'Is there anything in Python that can persistently check to see if an Outlook email with a certain subject title came in?

I want to know if there's anything in Python that can constantly read my Outlook messages every five minutes. I want it to just check my email every 5 minutes (3:05PM, 3:10PM, 3:15PM, etc.) and as soon as an email comes in my inbox saying with a subject line like "Hello what's up" I want Python to automatically trigger a piece of .py code.

What I know so far

I already know how to access Outlook -

import win32com.client
win32com.client.Dispatch('outlook.application')
mapi = outlook.GetNamespace("MAPI")
inbox = mapi.GetDefaultFolder(1)
...
...

Some possibilities

I am currently looking at a couple links such as persistently running Python in the background, listening for oncoming emails with Python, how to trigger a script upon email receipt as well as a Youtube video that talks about how to run a python script upon sending an email.

Hopefully I'll be able to figure out exactly how to run my Python script upon receipt of email, but in the meantime this question stays open. Thanks in advance.



Solution 1:[1]

The NewMailEx event of the Outlook Application class fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem. The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item.

In the NewMailEx event handler you may get an item instance received and check the Subject property.

You can either process the unread emails in the Inbox (see Items.Restrict or Items.Find/FindNext) assuming that new unprocessed messages are still unread or (in case of cached mode) use Items.ItemAdd event on the Inbox folder - it will fire when your OST file is being synchronized with the remote mailbox.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eugene Astafiev