0

Trying to Access a Shared Folder using the following code :

credentials = Credentials(username = user_name, password = "secret")
config = Configuration(server ='outlook.office365.com', credentials = credentials,  auth_type=NTLM)
account = Account(primary_smtp_address = 'shared_mail@domain.com', credentials = credentials, autodiscover = False, config = config, access_type = DELEGATE,)

The above three lines of Code work perfectly but we are unable to get the root, the following code : account.root.tree() or account.root throws the following error:

KeyError                                  Traceback (most recent call last)
    ~\anaconda3\lib\site-packages\cached_property.py in __get__(self, obj, cls)
         68                 # check if the value was computed before the lock was acquired
    ---> 69                 return obj_dict[name]
         70 
    KeyError: 'root'
    During handling of the above exception, another exception occurred:
    ErrorNonExistentMailbox                   Traceback (most recent call last)
    <ipython-input-46-a90a4f76ca21> in <module>
          2 logging.basicConfig(level=logging.DEBUG)
          3 
    ----> 4 account.root.tree()
    ~\anaconda3\lib\site-packages\cached_property.py in __get__(self, obj, cls)
         71             except KeyError:
         72                 # if not, do the calculation and release the lock
    ---> 73                 return obj_dict.setdefault(name, self.func(obj))
         74 
         75 
    ~\anaconda3\lib\site-packages\exchangelib\account.py in root(self)
        268     @threaded_cached_property
        269     def root(self):
    --> 270         return Root.get_distinguished(account=self)
        271 
        272     @threaded_cached_property
    ~\anaconda3\lib\site-packages\exchangelib\folders\roots.py in get_distinguished(cls, account)
        107             return cls.resolve(
        108                 account=account,
    --> 109                 folder=cls(account=account, name=cls.DISTINGUISHED_FOLDER_ID, is_distinguished=True)
        110             )
        111         except ErrorFolderNotFound:
    ~\anaconda3\lib\site-packages\exchangelib\folders\base.py in resolve(cls, account, folder)
        485     def resolve(cls, account, folder):
        486         # Resolve a single folder
    --> 487         folders = list(FolderCollection(account=account, folders=[folder]).resolve())
        488         if not folders:
        489             raise ErrorFolderNotFound('Could not find folder %r' % folder)
    ~\anaconda3\lib\site-packages\exchangelib\folders\collections.py in resolve(self)
        254         additional_fields = self.get_folder_fields(target_cls=self._get_target_cls(), is_complex=None)
        255         for f in self.__class__(account=self.account, folders=resolveable_folders).get_folders(
    --> 256                 additional_fields=additional_fields
        257         ):
        258             yield f
    ~\anaconda3\lib\site-packages\exchangelib\folders\collections.py in get_folders(self, additional_fields)
        317                 folders=self.folders,
        318                 additional_fields=additional_fields,
    --> 319                 shape=ID_ONLY,
        320         ):
        321             yield f
    ~\anaconda3\lib\site-packages\exchangelib\services\get_folder.py in call(self, folders, additional_fields, shape)
         32             **dict(
         33                 additional_fields=additional_fields,
    ---> 34                 shape=shape,
         35             )
         36         )):
    ~\anaconda3\lib\site-packages\exchangelib\services\common.py in _pool_requests(self, payload_func, items, **kwargs)
        538         for i, chunk in enumerate(chunkify(items, self.chunk_size), start=1):
        539             log.debug('Processing %s chunk %s containing %s items', self.__class__.__name__, i, len(chunk))
    --> 540             for elem in self._get_elements(payload=payload_func(chunk, **kwargs)):
        541                 yield elem
        542 
    ~\anaconda3\lib\site-packages\exchangelib\services\common.py in _get_elements_in_response(self, response)
        401     def _get_elements_in_response(self, response):
        402         for msg in response:
    --> 403             container_or_exc = self._get_element_container(message=msg, name=self.element_container_name)
        404             if isinstance(container_or_exc, (bool, Exception)):
        405                 yield container_or_exc
    ~\anaconda3\lib\site-packages\exchangelib\services\common.py in _get_element_container(self, message, response_message, name)
        360         # rspclass == 'Error', or 'Success' and not 'NoError'
        361         try:
    --> 362             raise self._get_exception(code=response_code, text=msg_text, msg_xml=msg_xml)
        363         except self.ERRORS_TO_CATCH_IN_RESPONSE as e:
        364             return e
    ErrorNonExistentMailbox: Mailbox does not exist.

The same code seems to be working here : https://medium.com/@theamazingexposure/accessing-shared-mailbox-using-exchangelib-python-f020e71a96ab

Also checked this thread https://github.com/ecederstrand/exchangelib/issues/391 and tried almost all the solutions but facing the same error.

Diptarka
  • 3
  • 5
  • Does `user_name` have permissions to access the `shared_mail@domain.com` mailbox? – Erik Cederstrand Aug 07 '20 at 04:34
  • Yes it does. There is a slight update in the situation, we were able to get the root command to work using a server called `plamail` (we got the idea from one of the warnings that it was throwing) but when trying to loop through `account.inbox.all()`, it is throwing this `ErrorNonExistentMailbox: The SMTP address has no mailbox associated with it.` – Diptarka Aug 07 '20 at 06:59
  • Maybe you only have access to `account.public_folders_root`, not `account.root`? – Erik Cederstrand Aug 10 '20 at 07:14
  • Also, when you are cross-posting the issue on multiple sites, please add a link so people can find any solutions in the future. Same question in exchangelib issue tracker: https://github.com/ecederstrand/exchangelib/issues/795 – Erik Cederstrand Aug 11 '20 at 10:16
  • Okay @Eric, will do that ! Will reply back with the solution or work around on both the sites. – Diptarka Aug 12 '20 at 07:11

0 Answers0