2

I think my question is a bit off. I read Google Mailbox via MailKit Thanks to this Answer. I want to read a mailbox with a search filter from-date to end-date.

E.g I want to read emails for June 2020 month like that

I have a lot of searches but failed to get enough information. Please help in this regard.

Abdul Haseeb
  • 514
  • 4
  • 13

1 Answers1

2

You can pass your search query to Gmail like this:

private MessageCollection GetMails(string mailBox, string searchPhrase, DateTime start, DateTime end)
    {
        string dateRange = $"after:{start.ToString("yyyy/MM/dd")} before:{end.AddDays(1).ToString("yyyy/MM/dd")}";
        string searchQuery = $"{dateRange} {searchPhrase}";
        Mailbox mails = Client.SelectMailbox(mailBox);
        MessageCollection messages = mails.SearchParse(searchQuery);
        return messages;
    }
Amir H. Bagheri
  • 1,416
  • 1
  • 9
  • 17