MailKit从Gmail中删除单个邮件 [英] MailKit Delete single message from gmail

查看:97
本文介绍了MailKit从Gmail中删除单个邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MailKit( https://github.com/jstedfast/MailKit )连接到谷歌应用程序通过IMAP,我怎么可以删除一条消息? (我很好,它已经转移到垃圾箱,只需要它的收件箱。



到目前为止,我已经连接,下载,解析消息体的链接。只需要这一个最后一个动作来获得我所需要的东西。



谢谢!

解决方案

要从IMAP服务器上的文件夹中删除邮件,您只需要这样做:

 客户端。 Inbox.AddFlags(new int [] {index},MessageFlags.Deleted); 

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

现在邮件标记为\在服务器上删除。



然后您就可以通过调用清除所有已删除项目的文件夹:

  client.Inbox.Expunge(); 
  if(client.Capabilities.HasFlag(ImapCapabilities.UidPlus))
client.Inbox.Expunge(new UniqueId [] {uid});


I am using MailKit (https://github.com/jstedfast/MailKit) to connect to google apps via imap, how can I delete a single message though ? (I am fine to have it moved to trash, just need it out of the inbox.

So far I have it connected, downloading, parsing links from message bodies. I just need this one last action to have what I need.

Thanks!

解决方案

To delete a message from a folder on the IMAP server, this is all you need to do:

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

or

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

Now the message is marked as \Deleted on the server.

You can then purge the folder of all deleted items by calling:

client.Inbox.Expunge ();

If you are using UIDs instead of indexes and the IMAP server supports the UIDPLUS extension (check the client.Capabilities), you can expunge just a selected set of messages like this:

if (client.Capabilities.HasFlag (ImapCapabilities.UidPlus))
    client.Inbox.Expunge (new UniqueId[] { uid });

这篇关于MailKit从Gmail中删除单个邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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