How can I start an email listener using the exchanger that starts when new mail is received?

I want to write a service that accepts a message from my Outlook account. I used to connect to Outlook exchangelib

but couldn't find how to start the Inbox Listener. Here is my code.

from exchangelib import DELEGATE, Account, Credentials
from creds import PASSWORD, USERNAME, EMAIL

creds = Credentials(
    username=USERNAME,
    password=PASSWORD)
account = Account(
    primary_smtp_address=EMAIL,
    credentials=creds,
    autodiscover=True,
    access_type=DELEGATE)

# Print first 100 inbox messages in reverse order
for item in account.inbox.all().order_by('-datetime_received')[:1]:
    print(item.subject, item.body, item.attachments)

      

This is a simple example I found and it returns me the last message from my inbox.

Please can you give me a link where I can find a solution or help me write a listening service?

+3


source to share


1 answer


The code you posted should work, but you need to define what a new email is (new arrivals since last check, unread messages, etc.). You can use the Ubuntu notifier script example as inspiration: https://github.com/ecederstrand/exchangelib/blob/master/scripts/notifier.py



+1


source







All Articles