我想检查特定的发件人电子邮件,并在它到达的任何地方自动处理
但是,可能会出现我的Outlook重新开始的情况,这意味着我收到发件人的邮件并标记为未读
为了连续监控特定主题的新邮件,我找到了以下代码
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.
p