How to search mails newer than a specific timestamp using Mailkit?

Viewed 2434

I am building a C# function to periodically fetch email messages from a local email server(hMailServer) and save to a database table.

var uid_list = await inbox.SearchAsync(SearchQuery.SentAfter(lastDateTime));

The problem is that it ignores the time part only compare date part. Question: how to search mails newer than a timestamp value using Mailkit?

1 Answers

If your IMAP server supports the WITHIN extension, you can use SearchQuery.YoungerThan (int seconds).

To check if your IMAP server supports this extension, you can do:

if (client.Capabilities.HasFlag (ImapCapabilities.Within)) { }

(where client is an ImapClient instance that is both connected to the IMAP server and in an authenticated state).

Related