![]() |
Outlook mail watcher - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Outlook mail watcher (/thread-8500.html) |
Outlook mail watcher - g_shanmuga - Feb-23-2018 Hi Guys, Greeting to all, i am new learner, i just want to write app, which monitors outlooks applications and parse the newly received mail, extract mail information. I have found some reference code for that task which i posted below. 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 body = mail.Body print(subject) print(body) try: # Taking all the "BLAHBLAH" which is enclosed by two "%". 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()I understand the code some how. But its is very useful if you explained in detailed manner. The problem i am facing is, the body of the mail is not fully received in the code "body = mail.Body". I want to extract the body of mail fully even though it is a large chain mail. More over i want to read tables also if its in mail body. Please provide your suggestion and ideas to solve this issue. Thanks for spending your time for reading my post. RE: Outlook mail watcher - nilamo - Mar-26-2018 Is there a reason you're interfacing with outlook, instead of just using imap to query the server directly? |