Search code examples
pythongmail-imapimaplib

Fetch unseen mails with python vom Gmail


with the python script below I try to fetch mails from gmail. Im my mailbox is only one unread message, but the script gives me the following output:

[b'330 332 335 337 339 340 341 ...... 450]

With an other provider an one unread Mail I get the output:

[b'13320]

And that's what I would expect.

Can someone help me, why does gmail print so many unseen mails? (No I haven't received about 80 mails in the last minutes.)

Thanks in advance!

Greetings Jan

import imaplib
from pprint import pprint
i=imaplib.IMAP4_SSL("imap.gmail.com")
i.login("[email protected]", "myPasswd")
i.select("INBOX")
result, data=i.uid("SEARCH", "UNSEEN")
print(data)


Solution

  • Shame on me! Max was right. Thats really embarrassing :-/

    I dont'know why gmail doesn't show conversions with unread mails as unread. On the left side of the web UI it just shows Inbox (1). When I changed the View to 'unseen first' I could see all the unread mails and it says Inbox (87). Even if I have the Standard-View activated I would expect that gmail shows me the right number of unread messages.

    So as you can see, gmail is not my main-mailbox. I've learned a lot in the last days... Thank you Max and abielita for helping me!!!