import imaplib
def read():
userName = "[email protected]"
password = "xxxx"
name = '[email protected]'
email_ids = [userName]
data = []
imap_server = imaplib.IMAP4_SSL("imap.gmail.com",993)
imap_server.login(userName, password)
imap_server.select('INBOX')
da = []
status, response = imap_server.status('INBOX', "(UNSEEN)")
unreadcount = int(response[0].split()[2].strip(').,]'))
print unreadcount
status, response = imap_server.search(None, '(FROM "[email protected]")')
email_ids = [e_id for e_id in response[0].split()]
for e_id in email_ids:
_, response = imap_server.fetch(e_id, '(UID BODY[TEXT])')
da.append(response[0][1])
print da
read()
How to organise the code above, to read only unread mails? Also, once we read them, how to mark the messages as read mail using Python?