Search code examples
pythonexchangelib

Exchangelib: Create subfolder of subfolder of inbox


Hello I'm currently working with exchangelib. Right now I want to create a subfolder of a subfolder of the inbox and I don't know if it's possible, yet. So I just want to ask if anyone knows more about my problem? My code for creating a subfolder of the inbox is simply:

from exchangelib import Credentials, Account, Folder

credentials = Credentials('[email protected]', 'password')
account = Account('[email protected]', credentials=credentials, autodiscover=True)
folder = Folder(parent=account.inbox, name="subfolder_name")
folder.save()
item.move(folder)

Solution

  • Creating subfolders is possible using exchangelib, and your example should work. If you want to create a sub-subfolder, just use the subfolder as parent:

    subfolder = Folder(parent=account.inbox, name="subfolder_name")
    subfolder.save()
    subsubfolder = Folder(parent=subfolder, name="subsubfolder_name")
    subsubfolder.save()