Search code examples
imapyahoomailkit

unable to get Yahoo mail by Message-ID using mailkit


I want to fetch mail item by Message-Id using following code.

     var messageId = messageIdStringValue.DecryptFromBase64();
          var newId = "<" + messageId + ">";
        var matches = Client.Inbox.Search(SearchQuery.HeaderContains("Message-ID", newId));
        foreach (var uid in matches)
        {

            var message = Client.Inbox.GetMessage(uid);

        }

It's working fine with Gmail by there is no result for Yahoo mail.I should mention that I can get All mail items but the problem is in fetching the single message.Am I doing something wrong?


Solution

  • Thanks to @jstedfast I've found that the best way for searching mail item is by UniqueId not by the Message-ID as the search command maybe return no result in that way for different servers. following code works fine for all servers:

     foreach (var item in Client.Inbox.Fetch(new[] { uId }, MessageSummaryItems.UniqueId | MessageSummaryItems.BodyStructure))
            {
              var message = Client.Inbox.GetMessage(item.UniqueId)
            }