Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing a shared mailbox #1146

Closed
iwilltry42 opened this issue Nov 30, 2022 · 2 comments
Closed

Accessing a shared mailbox #1146

iwilltry42 opened this issue Nov 30, 2022 · 2 comments

Comments

@iwilltry42
Copy link

Describe the bug

I have a shared mailbox, say foo@example.com and a real licensed user user@example.com.
User user has access to the shared mailbox as can be seen in OWA.

Running the script below always results in

INFO:exchangelib.autodiscover.discovery.base:Step 5: Checking response
Traceback (most recent call last):
  File "/home/thklein/git/github.com/smartfabrik/mail-client/src/app/main.py", line 28, in <module>
    account = Account(
  File "/home/thklein/.local/share/virtualenvs/mail-client-ABCd0oy1/lib/python3.10/site-packages/exchangelib/account.py", line 175, in __init__
    ).discover()
  File "/home/thklein/.local/share/virtualenvs/mail-client-ABCd0oy1/lib/python3.10/site-packages/exchangelib/autodiscover/discovery/base.py", line 104, in discover
    ad = self._quick(protocol=ad_protocol)
  File "/home/thklein/.local/share/virtualenvs/mail-client-ABCd0oy1/lib/python3.10/site-packages/exchangelib/autodiscover/discovery/pox.py", line 61, in _quick
    return self._step_5(ad=ad)
  File "/home/thklein/.local/share/virtualenvs/mail-client-ABCd0oy1/lib/python3.10/site-packages/exchangelib/autodiscover/discovery/base.py", line 366, in _step_5
    ad.raise_errors()
  File "/home/thklein/.local/share/virtualenvs/mail-client-ABCd0oy1/lib/python3.10/site-packages/exchangelib/autodiscover/properties.py", line 340, in raise_errors
    raise ErrorNonExistentMailbox("The SMTP address has no mailbox associated with it")
exchangelib.errors.ErrorNonExistentMailbox: The SMTP address has no mailbox associated with it

To Reproduce

from exchangelib import (
    OAuth2Credentials,
    Account,
    Configuration,
    OAUTH2,
    DELEGATE,
    Identity,
)
import settings

import logging as log

log.basicConfig(level=log.INFO)

log.info(f"Connecting to Exchange Server as {settings.MAIL_USER}")

credentials = OAuth2Credentials(
    client_id=settings.CLIENT_ID,
    client_secret=settings.CLIENT_SECRET,
    tenant_id=settings.TENANT_ID,
    identity=Identity(primary_smtp_address=settings.MAIL_USER),
)

config = Configuration(
    credentials=credentials, server="outlook.office365.com", auth_type=OAUTH2
)

account = Account(
    primary_smtp_address=settings.MAIL_SHARED_MAILBOX,
    credentials=credentials,
    config=config
    autodiscover=True,
    access_type=DELEGATE,
)

Expected behavior

Ability to browse the shared mailbox.
I can access the account itself using

account = Account(
    primary_smtp_address=settings.MAIL_USER,
    credentials=credentials,
    config=config
    autodiscover=True,
    access_type=DELEGATE,
)

But from there I also won't see the folders of the shared mailbox.

Additional context

Python 3.10, exchangelib 4.9.0

I'm super lost here and grateful for any help 🙏

@ecederstrand
Copy link
Owner

This actually doesn't have anything to do with shared mailboxes. The code is failing in the autodiscovery step, which happens before mailbox access.

Autodiscovery is not supported with the kind of OAuth token you're using. See https://learn.microsoft.com/en-us/exchange/troubleshoot/development/pox-autodiscover-not-supported-oauth-client-credentials-grant.

There are a couple of things you can try:

  1. Use the OAuth2LegacyCredentials credentials class
  2. Use the SOAP-based autodiscovery implementation, as described in https://github.com/ecederstrand/exchangelib/blob/master/CHANGELOG.md#490
  3. Skip autodiscovery altogether. Your configuration already points to the server you want to use, so autodiscovery doesn't make a lot of sense here.

@iwilltry42
Copy link
Author

iwilltry42 commented Nov 30, 2022

UPDATE 2: Using SOAP-based autodiscovery fixed it (and fixing my typo helped with the following errors).
Thanks for your support!


@ecederstrand great, thank you very much!
autodiscover="soap", fixed that issue.
However, I still get ErrorNonExistentMailbox: The SMTP address has no mailbox associated with it. when trying to access anything about mail of that shared mailbox account.
This is the account:

INFO:root:Found UserResponse(user_settings_errors={}, user_settings={'user_display_name': ' FOO', 'user_dn': '/o=ExchangeLabs/ou=Exchange Administrative Group (ABCDEFG)/cn=Recipients/cn=145134532145-foo', 'auto_discover_smtp_address': 'foo@example.com', 'ews_supported_schemas': 'Exchange2007, Exchange2007_SP1, Exchange2010, Exchange2010_SP1, Exchange2010_SP2, Exchange2013, Exchange2013_SP1, Exchange2015', 'mailbox_dn': '/o=ExchangeLabs/ou=Exchange Administrative Group (ABCDEFG)/cn=Configuration/cn=Servers/cn=2234ffg-1235-1234-1234-1234567@example.com/cn=Microsoft Private MDB', 'external_ews_url': 'https://outlook.office365.com/EWS/Exchange.asmx'})

I totally get if this is out of scope for an issue in your repo though. I just can't seem to find proper information on accessing shared mailboxes... Our old IMAP way doesn't work anymore unfortunately...

UPDATE:

  1. Didn't try that yet.
  2. Works as per above
  3. Returns error TransportError: No valid version headers found in response (ErrorNonExistentMailbox('The SMTP address has no mailbox associated with it.'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants