0
votes

I am building an application for sending emails from Gmail to Exchange mailbox using Gmail Rest Api. I have done the following things so far.

  1. I have successfully created source and destination mailboxes.
  2. I am able to send messages by calling messages.list and messages.get functions.
  3. To check for new emails, I have to loop through all messageIds, even those ones which I have already sent to Exchange mailbox.(i.e. message Ids of the older emails)
  4. I have made sure no duplicates emails are sent to Exchange mailbox.

Since I have to loop through all the messageIds in Gmail mailbox for checking new Emails, I might have a performance issue when the number of emails are large. I want to know if there is an efficient way to get only new emails where I don't have to loop through all the messageIds. One more thing, I am searching in only Inbox label for new email arrivals, is there any other Label I need to search in ? I believe new Emails arrive in Inbox, Important and Spam labels only, is there something else I need to know about it?

Before sending the Google emails to Exchange mailbox, I am putting them in a database table. To solve my problem, I am planning to add a datetime field in the email table to track down the new emails in a particular date and time. I am not sure this idea will work or not so I need an expert advice on this issue.

1

1 Answers

3
votes

Read comments for parameter q in Gmail API docs for Users.messages: list:

q
string
Only return messages matching the specified query. Supports the same query format as the Gmail search box. For example, "from:[email protected] rfc822msgid: is:unread".

May be is:unread might help you to list only new messages?