-2

I am receiving about 60 emails a week which I have to manually enter data into a csv file. I use Microsoft Outlook 2010 and have a subfolder in my inbox called 'Market Emails'. Within this subfolder I have emails that include a owner name, business name, and email that I need to write into a csv.

I am attempting to go this in Python, but I'm not sure if I am able to. Thanks for any help you can offer!

Maddie
  • 87
  • 1
  • 6

1 Answers1

0

This is quite a broad question but yes this is possible, with using the .NET COM interop

A StackOverflow post here goes over something similar that you could use the get the details from the email received.

Code from the above post:

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
            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() 

Excel

You would then continue to use interop for excel with quite an extensive tutorial here.

haddow64
  • 676
  • 1
  • 7
  • 24
  • 1
    Thank you haddow64, I was definitely getting stuck and trying to figure out if it was even possible - thank you! – Maddie Jan 04 '16 at 13:29
  • @haddow64 I am trying to implement your solution currently and can't seem to find documentation on DispatchWithEvents. May I check with you on it works? I will have to pass Outlook and a Class into DispatchWithEvents - if I have multiple functions within the class, which function does it call? Also, how do i know DispatchWithEvents would pass receivedItemsIDs into the OneNewMailEx function? Thank you! – AiRiFiEd Mar 02 '17 at 12:14