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.