AE.Net.Mail message.value为null [英] AE.Net.Mail message.value is null

查看:1185
本文介绍了AE.Net.Mail message.value为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AE.net.mail从Hotmail帐户下载附件。以下是code。   根据给定的条件的消息阵列获取所有邮件。问题是,message.Value属性每条记录是,除了第一条记录为空。

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", "xxx@hotmail.com",                "xxx", ImapClient.AuthMethods.Login, 993, true))
    {
        ic.SelectMailbox("INBOX");

        Lazy<MailMessage>[] messages = ic.SearchMessages(SearchCondition.From("xxx@yahoo.com"));

        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.

推荐答案

我会建议使用 MailKit 代替。这是一个更好的IMAP客户端实现,实际上取决于规格。

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

MailKit是建立在 MimeKit 这是最好的/最快/最强大的MIME解析器库顶.NET提供。它比OpenPOP.NET解析器快25倍,比SharpMimeTools 75X快,比Mail.dll快70倍,比MIMER 65X快,非常快于所有的MIME解析器包含在所有开源ImapClient实现外面的(也可能是好/比商用MIME解析器也更快)。

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).

无论MimeKit和MailKit基于标记化流解析器这不仅意味着他们比其他图书馆更快,这也意味着他们能够更好地符合规格,最重要的是,这意味着他们不需要读取整个响应从IMAP服务器到解析消息之前,一个巨大的字符串缓冲区 - MailKit从插座,由显著量较大的邮件减少了内存占用,直接解析消息

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 ("xxx@hotmail.com", "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 ("xxx@yahoo.com");
                    foreach (var uid in client.Inbox.Search (query, cancel.Token)) {
                        var message = client.Inbox.GetMessage (uid, cancel.Token);
                    }

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

这篇关于AE.Net.Mail message.value为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆