Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use GMAIL API query filter for datetime

Tags:

c#

gmail-api

I am using GMAIL API over REST interface to read mails from gmail server, my problem is when I am using date filter by giving a date as 'after:2014/8/20 before:2014/8/22' then the mails starting from 2014/8/20 12.30 PM onwards are downloaded (ideally it should consider mails from 12.00 AM). Mails from night 12.00 AM till noon 12.30 PM are skipped. I think server is using PST time zone. Can I specify time in the filter? or is there a way to specify time zone so that I get all the mails.

code used:

    UsersResource.MessagesResource.ListRequest      request         = null;
    ListMessagesResponse                            response        = null;
    request                 =   gmailServiceObj.Users.Messages.List(userEmail);
    String query            =   "after:" + FromDate.Date.ToString("yyyy/M/dd") + "   before:" + ToDate.Date.ToString("yyyy/M/dd") + " label:" + LabelID;  
    request.Q               =   query;             

Thanks, Haseena

like image 299
Haseena Parkar Avatar asked Aug 21 '14 13:08

Haseena Parkar


1 Answers

The behavior of the API in this regard should be the same as the web UI, can you verify if that's not the case? The search query params are listed here: https://support.google.com/mail/answer/7190?hl=en

It seems odd that it wouldn't deliver emails between 12:00AM and 12:30AM, what timezone is your client in? What's the timezone preference set to in the Gmail web interface for the user? You could try changing that preference and see if it helps? If not, one workaround I can think of is to have the filter from the day before and do the filtering client-side, as ugly as that is... :-/

like image 82
Eric D Avatar answered Oct 13 '22 01:10

Eric D