0
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
message = messages.GetFirst()
body_content = message.body
print body_content

I have an outlook email account. The inbox has a sub folder : calls I want to read email messages from this sub folder in python i am using win32com.client here is what i am doing. I can access inbox but not sub folder in that

petezurich
  • 9,280
  • 9
  • 43
  • 57
habeeba
  • 11
  • 1
  • 2
  • 1
    Welcome to StackOverflow, please see [Ask] and [help] to properly format your question to a specific one with an [MCVE]. – r.ook Nov 09 '18 at 19:41
  • I recommend using POP/IMAP for this. If you don't know what that is, read up on the subject (before you go pywin32) – Torxed Nov 09 '18 at 19:47
  • i am using win32com.client here is what i am doing. I can access inbox but not sub folder in that – habeeba Nov 09 '18 at 19:50
  • 1
    Possible duplicate of [Outlook using python win32com to iterate subfolders](https://stackoverflow.com/questions/40849742/outlook-using-python-win32com-to-iterate-subfolders) – Torxed Nov 09 '18 at 20:33

2 Answers2

2

You could try to traverse the list of folders in Inbox, like this:

inbox = outlook.GetDefaultFolder(6).Folders.Item("Your_Folder_Name")

For more information, please refer to this link:

How to access a subfolder in Outlook inbox in Python

Alina Li
  • 884
  • 1
  • 6
  • 5
0

you may use the following :

inbox = outlook.GetDefaultFolder(6).Folders['sub_folder_name']

Rahul Vaidya
  • 189
  • 2
  • 12