0
import imaplib

def read():
    username = "xxx@gmail.com"
    password = 'xxx'
    data = []
    imap = imaplib.IMAP4_SSL("imap.gmail.com", 993)
    imap.login(username, password)
    imap.select('INBOX')
    # Print all unread messages from a certain sender of interest
    status, response = imap.status('INBOX', "(UNSEEN)")
    unread_msg_nums = response[0].split()
    for e_id in unread_msg_nums:
        _, response = imap.fetch(e_id, '(UID BODY[TEXT])')
        data.append(response[0][1])

    for e_id in unread_msg_nums:
        imap.store(e_id, '+FLAGS', '\Seen')    
read()

Here my requirement is planing to get all emails which are unread and find the all the sender email addresses after that make the mail as read.Above code has errors. How to do this in python.

Bruno Gelb
  • 5,322
  • 8
  • 35
  • 50

0 Answers0