-1

So my question is can you use Python and/or Microsoft Graph to look into your outlook email and pull data out and put it into a excel document.

Here's what I'm trying to do, if there's anything way of doing it please feel free to let me know:

I want to create a folder in my outlook Inbox that get redirected emails. I'd like to make a script that looks at all those emails in that folder and extracts certain data within each email and puts it into a excel document.

Jackie
  • 1
  • 2

1 Answers1

1

For instance, you could set up a python script that is connected to the Outlook REST APIs. Get the access token by following the instruction in the above website and use the access token to login. You could set time intervals to re-check your message/mail box and process those data. There could be functions/parameters in the api which allows you to receive update automatically every n seconds (I have not looked into the details yet). Write your own process function to process data to mine the data for your own usage.

import time
def main():
    data = get_my_messages(<your_access_token>)
    time.sleep(5)
    process(data)
main()

Such examples python code could be found in the website above.

def get_my_messages(access_token):
  get_messages_url = graph_endpoint.format('/me/mailfolders/inbox/messages')

  # Use OData query parameters to control the results
  #  - Only first 10 results returned
  #  - Only return the ReceivedDateTime, Subject, and From fields
  #  - Sort the results by the ReceivedDateTime field in descending order
  query_parameters = {'$top': '10',
                      '$select': 'receivedDateTime,subject,from',
                      '$orderby': 'receivedDateTime DESC'}

  r = make_api_call('GET', get_messages_url, access_token, parameters = query_parameters)

  if (r.status_code == requests.codes.ok):
    return r.json()
  else:
    return "{0}: {1}".format(r.status_code, r.text)
justin kwan
  • 261
  • 1
  • 6