使用s22.dll和c#从消息中获取LastUID

时间:2015-06-06 17:35:43

标签: c# email imap

我跟着文章How to mark unseen last unread message S22.imap

但是我无法获得我的混乱的UID。

long abc = 0;

            using (ImapClient Client = new ImapClient("abc.com", 143, "abc@abc.com", "password", S22.Imap.AuthMethod.Login, false))
            {
                IEnumerable<uint> uids = Client.Search(SearchCondition.Unseen());

                IEnumerable<MailMessage> messages = Client.GetMessages(uids, FetchOptions.Normal);
                foreach (MailMessage msg in messages)
                {
                    string msgFrom = msg.From.ToString();
                    string To = msg.To.ToString();
                    string Subject = msg.Subject;

                    // here i want the UID of this messge "msg"
                    // so that i can use it in order to mark this
                    // message as marked.

                    abc = abc + 1;
                }
            }

我怎样才能获得这个UID?

1 个答案:

答案 0 :(得分:0)

我不知道如何在S22.Imap中获得您想要的内容,但是这里是如何使用MailKit(另一个.NET的开源IMAP库)来实现的:< / p>

long abc = 0;
using (ImapClient client = new ImapClient ()) {
    client.Connect ("abc.com", 143, false);
    client.Authenticate ("abc@abc.com", "password");

    client.Inbox.Open (FolderAccess.ReadWrite);

    var uids = client.Inbox.Search (SearchQuery.NotSeen);

    foreach (var uid in uids) {
        var message = inbox.GetMessage (uid);
        var msgFrom = message.From.ToString ();
        var to = message.To.ToString ();
        var subject = message.Subject;

        // mark the message as read/seen
        client.Inbox.AddFlags (uid, MessageFlags.Seen, true);

        abc = abc + 1;
    }
}

对于它的价值,S22.Imap似乎是一个废弃的项目(有很多错误都没有修复),你应该真正考虑使用MailKit - 它还有很多用户,更多功能,更少的错误,并得到积极维护(我说这是实际为S22.Imap提供补丁的人。)

希望有所帮助。

相关问题