I'm trying to get the last email receirved using exchangelib listener;
the probleme here is that the code not printing the seconde print(account.inbox.all().count()) ,
and the first print(account.inbox.all().count()) printinig it fine,
see the result below the code
creds = Credentials(
username="domaine\\user",
password="password"
)
def main():
print("started !")
config = Configuration(server='server', credentials=creds)
account = Account(
primary_smtp_address="mail",
autodiscover=False,
config=config,
access_type=DELEGATE,
default_timezone=UTC
)
listener = Listener(account)
print(account.inbox.all().count())
def new_messaged_received():
print("---------------------------------new mail arrived----------------------------------------------");
for item in account.inbox.all().only('subject').order_by('-datetime_received')[:1]:
print(item.subject)
listener.streaming_event_received += new_messaged_received
listener.listen(NewMailEvent)
the result after receirving a new email :
7503
---------------------------------new mail arrived----------------------------------------------