0

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("myMailAdress@gmail.com", "myPasswd")
i.select("INBOX")
result, data=i.uid("SEARCH", "UNSEEN")
print(data)
Jan
  • 1
  • 2
  • Do you have a whole conversation unread in gmail? IMAP shows individual messages, not collapsed conversations like the web UI. – Max Oct 19 '17 at 00:52

2 Answers2

0

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!!!

Jan
  • 1
  • 2
-1

Use Users.messages: list to list the messages in the user's mailbox. Here's an example. Also, refer from this tutorial: Extract emails from Gmail with Python via IMAP.

For example, to get a list of mailboxes on the server, we can call list():

rv, mailboxes = M.list()
if rv == 'OK':
    print "Mailboxes:"
    print mailboxes

A complete version of the above code is available in this gist.

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59