-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!

3
  • What you exactly want explain us a bit more Commented Dec 31, 2015 at 15:22
  • This is awfully broad; do you just want to know if this is possible with Python? Commented Dec 31, 2015 at 15:27
  • I think I want has he tried something Commented Dec 31, 2015 at 15:28

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you haddow64, I was definitely getting stuck and trying to figure out if it was even possible - thank you!
@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!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.