AE.Net.Mail message.value is null

I am using AE.net.mail for downloading attachments from hotmail account. following is code.
Messages array gets all mails according to given condition. The problem is that message.Value property for every record is null except the first record.

ImapClient ic = new ImapClient("imap-mail.outlook.com", "<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="463e3e3e062e29322b272f2a6825292b">[email protected]</a>",                "xxx", ImapClient.AuthMethods.Login, 993, true))
    {
        ic.SelectMailbox("INBOX");

        Lazy<MailMessage>[] messages = ic.SearchMessages(SearchCondition.From("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="daa2a2a29aa3bbb2b5b5f4b9b5b7">[email protected]</a>"));

        foreach (Lazy<MailMessage> message in messages)
        {
            MailMessage m = message.Value;
        }

  foreach (Attachment attachment in m.Attachments)
    {
        fileExtension = Path.GetExtension(attachment.Filename);
        attachment.Save(@"H:Demo" + fileName + Path.GetExtension(attachment.Filename));
    }
    }

I am not able to understand why. please guide. Thanx.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I would recommend using MailKit instead. It’s a much better IMAP client implementation that actually follows the specifications.

MailKit is built on top of MimeKit which is the best/fastest/most robust MIME parser library for .NET available. It is 25x faster than OpenPOP.NET’s parser, 75x faster than SharpMimeTools, 70x faster than Mail.dll, 65x faster than MIMER, and hugely faster than all of the MIME parsers included in all of the open source ImapClient implementations out there (and probably better/faster than the commercial MIME parsers as well).

Both MimeKit and MailKit are based on tokenizing stream parsers which not only means they are faster than the other libraries, it also means they can better conform to the specs and best of all, it means they do not need to read the entire response from the IMAP server into a huge string buffer before parsing the message – MailKit parses the message directly from the socket which reduces memory usage by a significant amount for large messages.

using System;
using System.Net;
using System.Threading;

using MailKit.Net.Imap;
using MailKit.Search;
using MailKit;
using MimeKit;

namespace TestClient {
    class Program
    {
        public static void Main (string[] args)
        {
            using (var client = new ImapClient ()) {
                var credentials = new NetworkCredential ("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2c5454546c444358414d4540024f4341">[email protected]</a>", "xxx");
                var uri = new Uri ("imaps://imap-mail.outlook.com");

                using (var cancel = new CancellationTokenSource ()) {
                    client.Connect (uri, cancel.Token);
                    client.Authenticate (credentials, cancel.Token);

                    // Open the Inbox folder
                    client.Inbox.Open (FolderAccess.ReadOnly, cancel.Token);

                    var query = SearchQuery.FromContains ("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a7dfdfdfe7dec6cfc8c889c4c8ca">[email protected]</a>");
                    foreach (var uid in client.Inbox.Search (query, cancel.Token)) {
                        var message = client.Inbox.GetMessage (uid, cancel.Token);
                    }

                    client.Disconnect (true, cancel.Token);
                }
            }
        }
    }
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x