Search code examples
c#emailimaptcpclient

Mark email as read using imap protocol Tcpclient


_imapSw.WriteLine("$ STATUS INBOX (unseen)");
_imapSw.WriteLine("$ SELECT INBOX");
_imapSw.Flush();

After getting email count of unseen.I want to mark email as read. Please tell me command to mark first email as read. `

_imapSw.WriteLine("$ FETCH " + index + " (body[header.fields (from subject date)])"); _imapSw.WriteLine("$ FETCH " + index + " body[text]");`

i can fetch email header and body but this is not marking email as read.


Solution

  • When selecting the inbox, you get the ID of the first unread/unseen mail.

    * FLAGS (\Answered \Flagged \Deleted \Seen \Draft NonJunk $Junk Junk $MDNSent $F
    orwarded)
    * OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft NonJunk $Junk Jun
    k $MDNSent $Forwarded \*)] Flags permitted.
    * 8421 EXISTS
    * 0 RECENT
    * OK [UNSEEN 3395] First unseen.
    * OK [UIDVALIDITY 47932578432] UIDs valid
    * OK [UIDNEXT 46214] Predicted next UID
    * OK [HIGHESTMODSEQ 1377] Highest
    

    Then you can use the store command to mark it as read:

    _imapSw.WriteLine("$ STORE 3395 +flags \\seen");
    _imapSw.Flush();