你可以尝试这个
import imaplib
obj = imaplib.IMAP4_SSL('imap.gmail.com', 993)
obj.login('username', 'password')
obj.select('Inbox') <-- it will return total number of mail in Inbox i.e
('OK', ['50'])
obj.search(None,'UnSeen') <-- it will return the list of uids for Unseen mails
Run Code Online (Sandbox Code Playgroud)