-1

I'm trying to find some emails in my Gmail mailbox, using imap_tools and specific criterias. This is my code:

import time
from imap_tools import MailBox, AND, A

with MailBox('imap.gmail.com').login('email', 'password', 'INBOX') as mailbox:
        time.sleep(3)
        while True:
            for msg in mailbox.fetch(AND(from_="some_domain", mark_seen=False)): 
        ...

when trying to use 'mark_seen=False' or 'reverse = True' , its giving me this error:

raise KeyError('"{}" is an invalid parameter.'.format(key))
KeyError: '"mark_seen" is an invalid parameter.'

How can I solve this?

1 Answers1

0

mark_seen is passed as criteria (possible criteria) instead of keyword argument (allowed kwargs) to the function. It should be:

for msg in mailbox.fetch(AND(from_="some_domain"), mark_seen=False):
Julian Fock
  • 98
  • 10
  • Mmh weird, because I found these methods on https://pypi.org/project/imap-tools/ – the_guy71639 Aug 04 '21 at 20:26
  • 1
    And I dont mean "seen", because that's just checking if the email was read before. – the_guy71639 Aug 04 '21 at 20:27
  • I checked the docs again and I was in confusion as well, missunderstanding you, that you wanted to add the criteria `seen`. But as I now see @crissal already corrected it. The docs you were refering to are right. – Julian Fock Aug 04 '21 at 21:37