简体   繁体   English

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

[英]Get LastUID from message using s22.dll and c#

i followed the article How to mark unseen last unread message S22.imap 我按照文章如何标记未见的最后未读邮件S22.imap

but i am not able to get the UID of my messge. 但我无法获取信息的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;
                }
            }

how can i get this UID ? 我如何获得此UID?

I don't know how to get what you want in S22.Imap, but here's how you would do it with MailKit (another open source IMAP library for .NET): 我不知道如何在S22.Imap中获得想要的东西,但是这是使用MailKit (用于.NET的另一个开源IMAP库)的方法:

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;
    }
}

For what it's worth, S22.Imap seems to be an abandoned project (with lots of bugs that aren't getting fixed), you should really look into using MailKit instead - it has a lot more users, more features, fewer bugs and is actively maintained (and I say that as someone who has actually contributed patches to S22.Imap). 值得一提的是,S22.Imap似乎是一个被遗弃的项目(许多错误尚未得到修复),您应该真正使用MailKit进行研究-它拥有更多的用户,更多的功能,更少的错误,并且积极维护(我是说实际上是为S22.Imap贡献了补丁的人)。

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM