Forum Discussion

vondie's avatar
vondie
Contributor
10 years ago

Why Isn't my Code Working? Opening Outlook in Python Script

I have a basic script that I found that should open Microsoft Outlook and read the last email received, then log the contents of the body. I keep getting a runtime error saying "Member Not Found." I ...
  • vondie's avatar
    9 years ago

    Thank you for the responses, everyone. I figured out my issue. The fixed code is below for anyone else that may have this issue in the future: 

     

     

    def check_email():
      msOutlook = Sys.OleObject["Outlook.Application"] # brackets instead of parenthesis
      
      mapi = msOutlook.GetNamespace("MAPI") # different approach for identification of the application
      
      inbox = mapi.Folders("<inbox name>").Folders("Inbox") 
      
      messages = inbox.Items
      message = messages.getLast() # gets most recent email received
      body_content = message.body #grabs the body contents