0

I'm trying to use exchangelib to access my exchange account and automate some tasks. I can use my credentials to log in and send messages but I can't print inbox list. The code I'm trying to run is:

from exchangelib import Credentials, Account, DELEGATE
class ExchangeConnecter:

    def __init__(self, credentials: Credentials, email: str) -> None:
        self.credentials = credentials
        self.email = email
        try:
            self.account = Account(
                primary_smtp_address=self.email,
                credentials=self.credentials,
                autodiscover=True,
                access_type=DELEGATE,
            )
        except:
            fatal_error = sys.exc_info()[0]
            print(f"error: {fatal_error}")

    def get_list(self):
        email_list = self.account.inbox.all()
        return email_list

#use your own exchange credentials to reproduce the issue
mail = "johndoe@example.com"
domain = "DOMAIN\\johndoe"
password = "somepassword"
credentials = Credentials(domain, password)

connecter = ExchangeConnecter(mail, credentials)
list = connecter.get_list()
print(type(list)) #None!?

When I try to use the returned object I get a TypeError: NoneType. I tried to check the documentation but I don't seem to find a mistake in this particular snippet of code.

  • there are undefined variables in the example code. the question needs sufficient code for a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) – D.L Aug 07 '23 at 09:42
  • I edited the question with more code, now if you use your own exchange credentials you should be able to reproduce the issue. – Federico Frontini Aug 07 '23 at 09:57
  • You also swapped the arguments to ExchangeConnecter and are not using the password anywhere, so the posted code could never work. Please remove all unnecessary code (e.g. the try/except), run the code, make sure it prints what you stated in the question, and then post the exact same code you ran. – Erik Cederstrand Aug 07 '23 at 10:03

0 Answers0