How do you count messages in your gmail ?

Here is the short and dirtyeasy way how to:

First we need to install IMAPClient which extends standard module:

sudo pip install IMAPClient

from imapclient import IMAPClient

server = IMAPClient('imap.googlemail.com', use_uid=True, ssl=True)
server.login('mymailbox@gmail.com', 'password')

for f in server.list_folders():
    if f[2] == '[Gmail]':
        continue
    server.select_folder(f[2])
    all = server.search('ALL', None)
    print('%s : %s' % (f[2], len(all)))

Leave a Reply

Your email address will not be published. Required fields are marked *


*