如何在电子邮件中获取“RE:”回复帖子

时间:2015-07-29 14:37:34

标签: c# mailkit

我正在使用'MailKit'从邮件服务器获取邮件。

http://solvedstack.com/questions/using-c-net-librarires-to-check-for-imap-messages-from-gmail-servers-closed

我使用的文字“我建议查看MailKit,因为它可能是最强大的邮件库,它是开源(MIT)。

关于MailKit的一个令人敬畏的事情是,所有网络API都是可取消的(我在任何其他IMAP库中都没有看到过。)

它也是我所知道的唯一支持消息线程的库。“

现在上面代码的问题是我无法获取消息回复。我已经根据邮件主题搜索了邮件,但我只收到了第一条消息,而不是消息中的其他回复。所以任何人都可以让我知道如何在电子邮件中获取回复帖子。

1 个答案:

答案 0 :(得分:1)

如果您的服务器支持THREAD扩展程序,则可能需要使用该扩展程序。

以下是您可以使用它的方式:

if (client.Capabilities.HasFlag (ImapCapabilities.Thread)) {
    var threads = client.Inbox.Thread (ThreadingAlgorithm.References, SearchQuery.All);

    // `threads' now holds the relationship of all messages in the Inbox
    // so that you can figure out which messages are replies to what
    // other message. Each MessageThread node will have a UniqueId that
    // you can use to get the message at that node and a list of
    // "children" (which are replies to that message).
}

如果您的IMAP服务器不支持THREAD扩展程序,则可以执行此操作以获得相同的结果:

var messages = client.Inbox.Fetch (0, -1, MessageSummaryItems.UniqueId |
    MessageSummaryItems.Envelope | MessageSummaryItems.References);
var threads = MessageThreader.Thread (ThreadingAlgorithm.References, messages);

如果您要查找对特定邮件的回复,则需要知道该邮件的UniqueId,然后搜索threads结构以查找匹配的UniqueId。如果该节点有任何Children,那么这些将是回复。

相关问题