+1 vote

I want to only retrieve a list of emails via IMAP in date range specified (based on the date the email was sent).

I have done quite a lot of searching on this site and online and can’t find an example for how to do this.

Does anyone have a sample to get me started or even point me to the method or class that I should be using to do this?

by

1 Answer

0 votes
 
Best answer

Use Expression.Since and Expression.SentSince along with Imap.Search method.

DateTime start = DateTime.Now.AddDays(-30);
List<long> uids = imap.Search(Expression.SentSince(start);

This returns back the UIDs within that range very quick.

You can combine 2 or more IMAP search expressions using Expresion.Or or Expresion.And.

Use Expression.Since to find emails whose internal date (disregarding time and timezone) is within or later than the specified date; Expression.SentSince to find messages whose [RFC-2822] Date: header (disregarding time and timezone) is within or later than the specified date. And matching Expression.Before and Expression.SentBefore queries.

by (300k points)
Date search with Yahoo IMAP not working
...