0

We can fetch a Gmail mailbox using Mailbox/IMAP_mailbox (imap-tools) as follows:

from imap_tools import MailBox as IMAP_mailbox

# Init
mailbox = IMAP_mailbox(HOST)
mailbox.login(username=USERNAME, password=PASSWORD)

# Fetch
messages = mailbox.fetch(AND(seen=SEEN), bulk=BULK, mark_seen=MARK_SEEN, limit=LIMIT)

Then we can iterate through the messages as follows:

for message in messages:
    print(message)

To mark the message as seen we can do the following:

mailbox.seen(message.uid, True)

However, instead of labelling it as seen, I would like assign a Gmail label to it. How can this be achieved? in this setup?

WJA
  • 6,676
  • 16
  • 85
  • 152

1 Answers1

1

You may use custom flag.

https://github.com/ikvk/imap_tools/issues/123

Adding gmail label not implemented.

Vladimir
  • 6,162
  • 2
  • 32
  • 36
  • 1
    Seems to be added now? https://github.com/ikvk/imap_tools/releases/tag/v0.42.0 – WJA Aug 10 '21 at 23:05