+1 vote

I have to read an email base of more than 20,000 emails, but most of them are old and the client does not want to delete any email from his mailbox, that is why I want to know if it is possible to just download the emails from a date range without having to go through the 20,000 emails and ask what is the date of each one to be able to filter.

In short, being able to import only the emails of the day.

by

1 Answer

0 votes
 
Best answer

Yes, you can perform an IMAP search before downloading:
https://www.limilabs.com/blog/how-to-search-imap-in-net

var uids = await imap.SearchAsync(
    Expression.And(
        Expression.Before(beforeDateTime),
        Expression.Since(sinceIncludedDateTime)));

Use Expression class exposes has all search conditions you can use:

Expression.Before
Creates criterion to find messages whose internal date (disregarding time and timezone), assigned by an IMAP server, is earlier than the specified date.

Expression.Since
Creates criterion to find emails whose internal date (disregarding time and timezone), assigned by an IMAP server, is within or later than the specified date.

Expression.SentBefore
Creates criterion to find messages whose "Date:" header (disregarding time and timezone) is earlier than the specified date.

Expression.SentSince
Creates criterion to find emails whose "Date:" header (disregarding time and timezone) is within or later than the specified date.

by (297k points)
...