1

I'm using IMAP and MailSystem.NET to read emails in c#. How do I search emails by message id? (msg.MessageId)

 using (Imap4Client imap = new Imap4Client()){
        imap.ConnectSsl(protocol, port);
        imap.LoginFast(email, password);

        Mailbox inbox = imap.SelectMailbox("INBOX");

        int[] mails= inbox.Search("UNSEEN");

        for (int i = 0; i < mailsUnread.Length; i++) {
            Message msg = inbox.Fetch.MessageObject(mailsUnread[i]);
            string subject = msg.Subject;
           string body = msg.BodyText.Text;

           string messageId= msg.MessageId; 

         }
 }

Thanks

1 Answers1

1

I would highly recommend using MailKit instead as it is a much much much more robust IMAP client library than MailSystem.NET... but...

The way you would search for messages based on the Message-Id header in MailSystem.NET is:

int[] mails = inbox.Search (string.Format ("HEADER \"MESSAGE-ID\" \"{0}\"", msg.MessageId));

Hope that helps.

jstedfast
  • 35,744
  • 5
  • 97
  • 110