Samuel Drescher
Samuel Drescher

Reputation: 685

Accessing Shared Outlook Subfolders With Python

I have a script that goes through and moves emails in personal subfolders to various network locations and archives the emails to keep my inbox clean.

I want to deploy this to the team as we have a shared email account, yet I can't access the shared folders in this shared account.

For Example, my folders in outlook are diagrammed below:

1. [email protected]
     - Inbox
          -Sub Folder 1
          -Sub Folder 2
2. sharedAccount
     - Inbox
          -Sub Folder 1

I can connect to my sub-folders just fine and the inbox for the shared account, but I can't get to the shared sub folder 1.

Any suggestions? I'm using Python 3.7 and Win32, code is shown below:

import win32com.client
    from datetime import datetime
    import time
    print('Archiving Emails')
    print('')
    outlook = win32com.client.Dispatch('Outlook.Application').GetNameSpace('MAPI')
    inbox = outlook.Folders('shared')
    inbox = inbox.Folders('Inbox')
    test = outlook.Folders('shared').Folders('Inbox').Folders.Item('sub folder 1')

This works fine and lets me access the emails when I point it to my account, but fails at the test line when I point it to the shared email

Any suggestions?

Upvotes: 0

Views: 2845

Answers (1)

Ankita
Ankita

Reputation: 93

Gets inside the Folder for the Shared Mailbox:

     folder = outlook.Folders.Item("NameofYourSharedFolder")

To access the Inbox of the Shared Mailbox:

     inbox = outlook.GetSharedDefaultFolder(6)

To access another Folder within the Shared Mailbox:

     archiveFolder = folder.Folders.Item("MyArchive")

Upvotes: 1

Related Questions