简体   繁体   English

C#MailKit如何从邮件服务器(IMAP)删除电子邮件

[英]c# MailKit how to delete an email from mail server (IMAP)

I've found this: 我发现了这一点:

client.Inbox.AddFlags (new int[] { index }, MessageFlags.Deleted);
or
client.Inbox.AddFlags (new UniqueId[] { uid }, MessageFlags.Deleted);

then
client.Inbox.Expunge ();

I don't know how to obtain index or uid to use here. 我不知道如何获取索引或uid在这里使用。 My client works like this: 我的客户是这样的:

using (var client = new ImapClient())
{
                client.Connect(serverM.Text, Convert.ToInt32(portM.Text), true);
                client.AuthenticationMechanisms.Remove("XOAUTH");
                client.Authenticate(user.Text, pass.Text);
                var inbox =  client.GetFolder(inbox.Text);
                inbox.Open(FolderAccess.ReadWrite);
                var message = inbox.GetMessage(i);
                for (int i = 0; i < inbox.Count; i++) // 
                {
                    var message = inbox.GetMessage(i);
                    ...
                }
}

Also int I is not the index. 另外int我不是索引。 message.MessageID not equal to UID. message.MessageID不等于UID。 Where is my mistake? 我的错误在哪里?

You are using the index here: 您在这里使用索引:

for (int i = 0; i < inbox.Count; i++) // 
{
    var message = inbox.GetMessage(i);
    ...
}

i is the index. i是指数。

In more recent versions of MailKit, I added the ability to do: 在MailKit的最新版本中,我添加了以下功能:

inbox.AddFlags (i, MessageFlags.Deleted);

So now you don't need to do this: 所以现在您不需要这样做:

inbox.AddFlags (new int[] { i }, MessageFlags.Deleted);

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

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