I want to read out the newest E-Mail in the inbox, select the attachment out of it and move the E-Mail to a folder. I already have a code to save the attachment:
from exchangelib import Credentials, Account
import os
credentials = Credentials('[email protected]', 'password')
account = Account('[email protected]', credentials=credentials, autodiscover=True)
for item in account.inbox.all().order_by('-datetime_received')[:1]:
for attachment in item.attachments:
fpath = os.path.join("C:/destination/path", attachment.name)
with open(fpath, 'wb') as f:
f.write(attachment.content)
But I have a problem to move the E-Mail to another folder than the inbox. So far I only found this option:
item.move(to_folder)
But I don`t know how I should write in the name of the folder. Could anyone give me an example for this?
Thanks in advance.