Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Outlook mail watcher
#1
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.
Reply
#2
Is there a reason you're interfacing with outlook, instead of just using imap to query the server directly?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Search Outlook Inbox for set of values cubangt 1 1,084 Jun-28-2023, 09:29 PM
Last Post: cubangt
  Save image from outlook email cubangt 1 699 Jun-07-2023, 06:52 PM
Last Post: cubangt
  Mark outlook emails as read using Python! shane88 2 6,557 Feb-24-2022, 11:19 PM
Last Post: Pedroski55
  Trying out the parsing/reading of emails from my outlook cubangt 0 6,171 Jan-12-2022, 08:59 PM
Last Post: cubangt
  Need Outlook send email code using python srikanthpython 3 8,240 Feb-28-2021, 01:53 PM
Last Post: asyswow64
  Mail issue Mihil 3 2,661 Dec-03-2020, 05:25 AM
Last Post: Mihil
  reading shared outlook emails zarize 0 2,451 Mar-03-2020, 01:47 PM
Last Post: zarize
  smtplib mail without subject anna 2 2,474 Apr-24-2019, 05:44 AM
Last Post: anna
  Reading email messages on Outlook johnjohn 9 34,858 Apr-03-2019, 10:41 AM
Last Post: Ken2702
  [Outlook] How to delete items from To-Do List? Winfried 1 3,408 Oct-19-2018, 09:05 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020