0

I was accessing Outlook using python and got [COMObject unknown].

# https://www.codeforests.com/2020/06/04/python-to-read-email-from-outlook/

import win32com.client
outlook = win32com.client.Dispatch('outlook.application')
mapi = outlook.GetNamespace("MAPI")

# print all outlook mail id
for account in mapi.Accounts:
    print(account.DeliveryStore.DisplayName)

# 6 means index refer to https://learn.microsoft.com/en-us/office/vba/api/outlook.oldefaultfolders
inbox = mapi.GetDefaultFolder(6)
messages = inbox.Items

print(messages)  # giving <COMObject <unknown>>

Last line gives

Unknown error.

1 Answer 1

1
inbox = mapi.GetDefaultFolder(6)
messages = inbox.Items
message = messages.GetFirst()
while message:
    print(message.Subject)
    message = messages.GetNext()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.