1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/usr/bin/python import imaplib import email M=imaplib.IMAP4_SSL("imap.whatever.com", 993) M.login("username","password") status, counts = M.status("INBOX","(MESSAGES UNSEEN)") if status == "OK": unread = int(counts[0].split()[4][:-1]) else: unread = "N/A" print(unread)