1

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('test.example@mail.com', 'password')
account = Account('test.example@mail.com', credentials=credentials, autodiscover=True)
folder = Folder(parent=account.inbox, name="subfolder_name")
folder.save()
item.move(folder)
O. Schultz
  • 155
  • 1
  • 3
  • 12

2 Answers2

1

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()
Erik Cederstrand
  • 9,643
  • 8
  • 39
  • 63
0

Now that I can test the code, because the CASError as mentioned in Github is gone at least for today, I get a "ValueError: Unsupported type for value None on elem " when I run the code. My code is:

 subfolder = Folder(parent=account.inbox, name="RFS")
 subsubfolder = Folder(parent=subfolder, name="RFS_1150-1199")
 subsubfolder.save()
 folder = Folder(parent=subsubfolder, name=wordfile)
 folder.save()
 item.move(folder)
O. Schultz
  • 155
  • 1
  • 3
  • 12
  • Please post the full stack trace so we can see exactly where the exception occurs. – Erik Cederstrand May 24 '18 at 12:10
  • Unfortunately I can't try it out right now, because of the CASError, but I know that the problem occurs in this line: "subsubfolder = Folder(parent=subfolder, name="RFS_1150-1199")" as far is I can remember – O. Schultz May 24 '18 at 12:19
  • You probably need to also set the `account` argument when creating the Folder. – Erik Cederstrand May 24 '18 at 21:20
  • Sorry that I haven't answered your comment till now, but I had some other tasks to do in the past weeks. How can I set the account argument? Could you please give me an example? – O. Schultz Jun 07 '18 at 13:17
  • Try `Folder(account=account, parent=account.inbox, name="RFS")` – Erik Cederstrand Jun 10 '18 at 13:44
  • Okay now it works out really fine with that Code: folder = Folder(account=account, parent=account.inbox, name="RFS") folder.save() subfolder = Folder(account=account, parent=folder, name="RFS_1150-1199") subfolder.save() subsubfolder = Folder(account=account, parent=subfolder, name=item.subject) subsubfolder.save() item.move(subsubfolder) Again thanks for helping me out. – O. Schultz Jun 11 '18 at 13:00
  • And how can I create a new subfolder of my subfolder in a new run, to move the next incoming email over there? I only get a ValueError while running this: subfolder = Folder(account=account, parent=folder, name="RFS_1150-1199") subsubfolder = Folder(account=account, parent=subfolder, name="RFS_1195") subsubfolder.save() – O. Schultz Jun 12 '18 at 08:09
  • You'll have to post the ValueError. Also, if you're not on the latest version of exchangelib already, try upgrading to 1.11.4. – Erik Cederstrand Jun 12 '18 at 09:33
  • ValueError: Unsupported type for value None on elem , I've already upgraded exchangelib to 1.11.4 – O. Schultz Jun 12 '18 at 10:52
  • Probably you forgot to save `subfolder`. At least your example code in the original question doesn't do that. – Erik Cederstrand Jun 13 '18 at 09:06
  • The problem is, that if I save the folders again in the second run, I get the "ErrorFolderExists: A folder with the specified name already exists., Could not create folder RFS." error, what I want is just to get into the subfolder and create another folder into that – O. Schultz Jun 13 '18 at 09:18
  • Then just try to get the folders by name first. E.g.: `subfolder = account.inbox / 'RFS'`. If that fails with `ErrorFolderNotFound`, then create the folder instead: `subfolder = Folder(parent=account.inbox, name="RFS").save()`. – Erik Cederstrand Jun 13 '18 at 09:28
  • The second example is basically the same way, I've tried it before so that doesn't work. But the first example you gave me worked out fine and now I can create another folder as I wanted it to, so hopefully for the last time now, thank you very much for all the help. – O. Schultz Jun 13 '18 at 10:57