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('', use_uid=True, ssl=True)
server.login('', 'password')

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

Leave a Reply

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