1

I have been using the below code to access a public folder in Outlook:

import win32com.client
import datetime


outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

inbox = outlook.GetDefaultFolder(18).Folders.Item("xxxxx")
messages = inbox.Items
date = datetime.date.today()


subject = "xxxxxxx"

for message in messages:
    if subject in message.subject and date in message.senton.date():
     print(message.senton.time())

However, our Outlook has been moved from an Exchange server to the cloud and public folders have been changed to shared folders (I think?). The above code no longer works and I get the below error:

pywintypes.com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft Outlook', 'The attempted operation failed.  An object could not be found.', None, 0, -2147221233), None)

Is there any way to search emails from a shared mailbox?

Thanks

1 Answer 1

1

Try this:

inbox = outlook.Folders("Name of Shared Folder").Folders.Item("xxxxx")

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

5 Comments

Awesome! That seems to have worked, I have one more question though. I can't seem to download attachments from emails with the code I was previously using on the old folder. I have updated my question with the code to download attachments. Would you have any idea how?
okay never mind, I think I will post a separate question. Thanks again for the help!
You can use attachments = message.Attachments Then to test it works, print the name of the attachements: for i in range(attachments.Count): attachment = attachments.Item(i+1) print(attachment)
Okay awesome, do you have any idea how to specify to download only excel attachments for example? And ignore pdfs etc?
I would recommend using the find() function on the string and look for ".xlsx" or ".pdf". Good luck!

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.