Marking emails as read in Outlook using O365 and Python

84 Views Asked by At

I am trying to mark emails as read in Outlook using the O365 library and Python. I am using the message.is_read property to mark the message as read, but it doesn't seem to be working. The messages are still being returned as unread every time I run my script.

Here's the relevant code snippet:

def access_mail_box(account):
    try:
        mailbox= account.mailbox()
        inbox= mailbox.inbox_folder()
        query = mailbox.new_query().on_attribute('isRead').equals(False) #get unread messages
        messages = inbox.get_messages(query=query,limit=config['limit'])
        return messages
    except Exception as e:
        print(f"Error in access_mail_box function: {e}")
        raise e


account = Account(credentials=(client_id, client_secret), token_backend=token_backend)
messages = access_mail_box(account)

# loop through messages and mark as read
for message in messages:
    message.is_read = True
    message.unread = False

I tried to mark emails as read then retrieve the new unread emails but message.is_read = True and message.unread = False don't help

1

There are 1 best solutions below

0
On
message.mark_as_read()

worked fine