#!/usr/local/bin/python from imap_tools import MailBox, Q # get list of email subjects from INBOX folder with MailBox('imap.gmail.com').login('dear.jsu@gmail.com', 'Jsayshree_958_') as mailbox: subjects = [msg.subject for msg in mailbox.fetch()] # OR the same otherwise #mailbox = MailBox('imap.mail.com') #mailbox.login('test@mail.com', 'password', initial_folder='INBOX') #subjects = [msg.subject for msg in mailbox.fetch(Q(all=True))] mailbox.logout()