Home > Net >  Read Google Mail Box through Search Filter like Date
Read Google Mail Box through Search Filter like Date

Time:09-18

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.

CodePudding user response:

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;
    }
  • Related