Search code examples
python-3.xemailimap

In Python 3.4.3, How to send flag 'Seen' with IMAP protocol


  1. Get Mail list that flag 'UNSEEN'
  2. Read each of the mails
  3. leave a flag 'Seen' that I manufactured one.

I want to set a mail up flag 'Seen' in my email account. How can i set up 'Seen' Flag in python.

Do you have any idea?

import imaplib

emailConnection = imaplib.IMAP4_SSL() 
emailConnection.login(id, password)

emailConnection.select(configData['email_input_folder']) 

result, data = emailConnection.uid('SEARCH', None, '(UNSEEN)')
uids = data[0].split()
for uid in uids:
    result, data = emailConnection.uid('fetch', uid, '(RFC822)') 
    # ------   data is manufactured.
    result = emailConnection.store(uid, '+FLAGS', '\\Seen')  # << Occured Exception

In My Error Message is printed like this.

[DEBUG|imap.py:81]2017-02-24 21:43:57,921 > STORE command error: BAD [b'Error in IMAP command STORE: Invalid messageset'] 

Solution

  • You're mixing UID and Sequence Sets.

    If you use UID SEARCH and UID FETCH, you need to use UID STORE:

    result = emailConnection.uid("STORE", uid, '+FLAGS', '\\Seen')