PeterSmith.Org

Listing GMail folders

    I have been playing around with moving my email reading into Emacs. In doing so, it was useful to see what 'folders' I had on Gmail. So, I put together this quick and dirty script.

    
    import email
    import imaplib
    import sys
    import pprint
    
    host= 'imap.gmail.com'
    
    username= 'anyone@gmail.com'
    password= 'mmuuppeettss'
    
    mail= imaplib.IMAP4_SSL(host)
    
    try:
        rc, data = mail.login(username, password)
    except imaplib.IMAP4.error:
            print ('Login failed :(')
            sys.exit(1)
    
    print(rc, data)
    
    rc, mailboxes = mail.list()
    
    if rc == 'OK':
            print('Mailboxes:')
            print(mailboxes)
    else:
            pprint('Failed to get mailboxes: {}'.format(rc))

    Webmentions
    If you webmention this page, please let me know the URL of your page.

    BTW: Your webmention won't show up until I next "build" my site.

    Word count: 100 (about 1 minutes)

    Published:

    Updated: 16 Jun '17 11:03

    Author: Peter Smith

    Permalink: https://petersmith.org/blog/2017/06/16/list-gmail-folders/

    Section: blog

    Kind: page

    Bundle type: leaf

    Source: blog/2017/06/16/listing-gmail-folders/index.org